Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp3847152rwe; Mon, 17 Apr 2023 04:36:03 -0700 (PDT) X-Google-Smtp-Source: AKy350a4ZO3rC0y2hc2KyjQfdOXvAfrJ3N+sbhhgZF2KkPalJIiAQWnm9iTf3ogmqSYIMisj3BMM X-Received: by 2002:a05:6a20:8e28:b0:f0:2cb8:7d45 with SMTP id y40-20020a056a208e2800b000f02cb87d45mr1441261pzj.11.1681731363636; Mon, 17 Apr 2023 04:36:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681731363; cv=none; d=google.com; s=arc-20160816; b=GYqBy91bUS+kUn+R72ksawH+JNVUn+YKnI64ZTQkp+1rJKWA7gEKImzRsleVn5aFS4 qq620RvVWMzlVs29fjXqLFpfW+Hj4DDvTX5BLtewZT4kGHTBNyKxvBRJbJni7eVOex1p u2XTlGaqfDJgwX0oG4/qbGKPXKNu9wQW53/fFSkFw7WUMfpIwBOcGuWrllTeDd7T6xbr NCHoqyPK6yGHmTw2PryuZ8b1tclQFzHmOJegAQcHBNE1GPHLSS0luZQoqzL+pQLwi7CF /Oh01RSz6LzZqU5GMLdLW6MkBmcBKwfmtzImR1RUm4oUy+yI6FSGyS2kq/vpXCEaI3u3 7vAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=M1Q82Roz42OPHZlHxq9vgIdt8tbFUEU3QEd3VndCNz0=; b=b97+nh1AcuHreLwwCcYGvvOB8vwdd/AlgWxXrVS4ABdkEXt3BoV20ngXKO4zqs8lxC hSnelsNzBNgIDR0+XpdE2tbA25qW4hNgS4EGxGSa3hGiICIABRBhsA8KjhCUpea4sfFR 91WH/nCyuUlPuU7f6WGkAf5fMJSdEuhUvX9tL8nzj4Ka9hkAgzXdwpwvuqW3K4/aTdgQ 7UYBwlrU36Wx6Qh+wygR06/5AFPrsVXUkiws2sePl2iAK8Oe6BORtNg+Br/4SuSjeqYy XWfZrAjamdeer7+DhJgTeCMd5asFdYNt5zdY4MA+hnvPhBlj93zT590MzKGAVFlwz3jn G6Dw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o9-20020a655209000000b005194ff488d9si11339985pgp.516.2023.04.17.04.35.52; Mon, 17 Apr 2023 04:36:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230410AbjDQL3b (ORCPT + 99 others); Mon, 17 Apr 2023 07:29:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230171AbjDQL3a (ORCPT ); Mon, 17 Apr 2023 07:29:30 -0400 Received: from outbound-smtp51.blacknight.com (outbound-smtp51.blacknight.com [46.22.136.235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D1E4272A for ; Mon, 17 Apr 2023 04:28:36 -0700 (PDT) Received: from mail.blacknight.com (pemlinmail04.blacknight.ie [81.17.254.17]) by outbound-smtp51.blacknight.com (Postfix) with ESMTPS id 2B1A6FA943 for ; Mon, 17 Apr 2023 12:13:54 +0100 (IST) Received: (qmail 19061 invoked from network); 17 Apr 2023 11:13:54 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.21.103]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 17 Apr 2023 11:13:54 -0000 Date: Mon, 17 Apr 2023 12:13:52 +0100 From: Mel Gorman To: Wen Yang Cc: Andrew Morton , Oscar Salvador , William Lam , Fu Wei , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: compaction: optimize compact_memory to comply with the admin-guide Message-ID: <20230417111352.v26slrcmz4qo3tnn@techsingularity.net> References: <20230411134801.a4aadef5aba0f51e0d44bb7a@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 16, 2023 at 01:42:44AM +0800, Wen Yang wrote: > > ??? 2023/4/13 00:54, Wen Yang ??????: > > > > ??? 2023/4/12 04:48, Andrew Morton ??????: > > > On Wed, 12 Apr 2023 02:24:26 +0800 wenyang.linux@foxmail.com wrote: > > > > > > > For the /proc/sys/vm/compact_memory file, the admin-guide states: > > > > When 1 is written to the file, all zones are compacted such that free > > > > memory is available in contiguous blocks where possible. This can be > > > > important for example in the allocation of huge pages although > > > > processes > > > > will also directly compact memory as required > > > > > > > > But it was not strictly followed, writing any value would cause all > > > > zones to be compacted. In some critical scenarios, some applications > > > > operating it, such as echo 0, have caused serious problems. > > > Really?? You mean someone actually did this and didn't observe the > > > effect during their testing? > > > > Thanks for your reply. > > > > Since /proc/sys/vm/compact_memory has been well documented for over a > > decade: > > > > https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/Documentation/admin-guide/sysctl/vm.rst#n109 > > > > > > it is believed that only writing 1 will trigger trigger all zones to be > > compacted. > > > > Especially for those who write applications, they may only focus on > > documentation and generally do not read kernel code.? Moreover, such > > problems are not easily detected through testing on low pressure > > machines. > > > > Writing any meaningful or meaningless values will trigger it and affect > > the entire server: > > > > # echo 1 > /proc/sys/vm/compact_memory > > # echo 0 > /proc/sys/vm/compact_memory > > # echo dead > /proc/sys/vm/compact_memory > > # echo "hello world" > /proc/sys/vm/compact_memory > > > > The implementation of this high-risk operation may require following the > > admin-guides. > > > > -- > > > > Best wishes, > > > > Wen > > > > > Hello, do you think it's better to optimize the sysctl_compaction_handler > code or update the admin-guide document? > Enforce the 1 on the unlikely chance that the sysctl handler is ever extended to do something different and expects a bitmask. The original intent intent of the sysctl was debugging -- demonstrating a contiguous allocation failure when aggressive compaction should have succeeded. Later some machines dedicated to batch jobs used the compaction sysctl to compact memory before a new job started to reduce startup latencies. Drop the justification "In some critical scenarios, some applications operating it, such as echo 0, have caused serious problems." from the changelog. I cannot imagine a sane "critical scenario" where an application running as root is writing expected garbage to proc or sysfs files and then surprised when something unexpected happens. -- Mel Gorman SUSE Labs