From patchwork Thu Apr 22 13:37:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charan Teja Kalla X-Patchwork-Id: 12218497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-21.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B0C1C433ED for ; Thu, 22 Apr 2021 13:38:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B7D9D61425 for ; Thu, 22 Apr 2021 13:38:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B7D9D61425 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 28FEF6B006C; Thu, 22 Apr 2021 09:38:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 23F926B006E; Thu, 22 Apr 2021 09:38:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 092856B0070; Thu, 22 Apr 2021 09:38:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0128.hostedemail.com [216.40.44.128]) by kanga.kvack.org (Postfix) with ESMTP id D8B286B006C for ; Thu, 22 Apr 2021 09:38:24 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8C0188248047 for ; Thu, 22 Apr 2021 13:38:24 +0000 (UTC) X-FDA: 78060107328.14.78C20B7 Received: from so254-9.mailgun.net (so254-9.mailgun.net [198.61.254.9]) by imf16.hostedemail.com (Postfix) with ESMTP id C335980192F6 for ; Thu, 22 Apr 2021 13:38:20 +0000 (UTC) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1619098703; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=Z55UTxpXyLr3rTUJNaY6VLLVuJYlMNUJ66KfV5/0zQU=; b=CaW3c6zjWsGY6TubU1lewYcT/QTuuTIijI+UNLxYtGZD+p8DPo+MMbfR2Eq8aadHp5fS2LJY DIYder1qCGj25gwpnXhcbmsUIl52BxrNxG3F0IEqd4TYQ6B/VefhNeVbsSn6ieeJSQYL4rdA mYENAKIDjrLEy0YpA5FKXc+AJHk= X-Mailgun-Sending-Ip: 198.61.254.9 X-Mailgun-Sid: WyIwY2Q3OCIsICJsaW51eC1tbUBrdmFjay5vcmciLCAiYmU5ZTRhIl0= Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n03.prod.us-west-2.postgun.com with SMTP id 60817c45e0e9c9a6b6d2263c (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Thu, 22 Apr 2021 13:38:13 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 3B97EC4338A; Thu, 22 Apr 2021 13:38:13 +0000 (UTC) Received: from hu-charante-hyd.qualcomm.com (unknown [202.46.22.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: charante) by smtp.codeaurora.org (Postfix) with ESMTPSA id 4537CC433F1; Thu, 22 Apr 2021 13:38:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 4537CC433F1 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=charante@codeaurora.org From: Charan Teja Reddy To: akpm@linux-foundation.org, vbabka@suse.cz, bhe@redhat.com, nigupta@nvidia.com, khalid.aziz@oracle.com, mateusznosek0@gmail.com, sh_def@163.com, iamjoonsoo.kim@lge.com, mcgrof@kernel.org, keescook@chromium.org, yzaikin@google.com, mhocko@suse.com, rientjes@google.com, mgorman@techsingularity.net Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, vinmenon@codeaurora.org, Charan Teja Reddy Subject: [PATCH] mm: compaction: improve /proc trigger for full node memory compaction Date: Thu, 22 Apr 2021 19:07:58 +0530 Message-Id: <1619098678-8501-1-git-send-email-charante@codeaurora.org> X-Mailer: git-send-email 2.7.4 X-Rspamd-Queue-Id: C335980192F6 X-Stat-Signature: wu79ragonampu4hzfzof9ycenfdipd6m X-Rspamd-Server: rspam02 Received-SPF: none (mg.codeaurora.org>: No applicable sender policy available) receiver=imf16; identity=mailfrom; envelope-from=""; helo=so254-9.mailgun.net; client-ip=198.61.254.9 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1619098700-802775 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The existing /proc/sys/vm/compact_memory interface do the full node compaction when user writes an arbitrary value to it and is targeted for the usecases like an app launcher prepares the system before the target application runs. The downside of it is that even if there are sufficient higher order pages left in the system for the targeted application to run, full node compaction will still be triggered thus wasting few CPU cycles. This problem can be solved if it is known when the sufficient higher order pages are available in the system thus full node compaction can be stopped in the middle. The proactive compaction[1] can give these details about the availability of higher order pages in the system(it checks for COMPACTION_HPAGE_ORDER pages, which usually be order-9) thus can be used to trigger for full node compaction. This patch adds a new /proc interface, /proc/sys/vm/proactive_compact_memory, and on write of an arbitrary value triggers the full node compaction but can be stopped in the middle if sufficient higher order(COMPACTION_HPAGE_ORDER) pages available in the system. The availability of pages that a user looking for can be given as input through /proc/sys/vm/compaction_proactiveness. [1]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=facdaa917c4d5a376d09d25865f5a863f906234a Signed-off-by: Charan Teja Reddy --- include/linux/compaction.h | 3 +++ kernel/sysctl.c | 7 +++++++ mm/compaction.c | 25 ++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/include/linux/compaction.h b/include/linux/compaction.h index ed4070e..af8f6c5 100644 --- a/include/linux/compaction.h +++ b/include/linux/compaction.h @@ -82,9 +82,12 @@ static inline unsigned long compact_gap(unsigned int order) #ifdef CONFIG_COMPACTION extern int sysctl_compact_memory; +extern int sysctl_proactive_compact_memory; extern unsigned int sysctl_compaction_proactiveness; extern int sysctl_compaction_handler(struct ctl_table *table, int write, void *buffer, size_t *length, loff_t *ppos); +extern int sysctl_proactive_compaction_handler(struct ctl_table *table, + int write, void *buffer, size_t *length, loff_t *ppos); extern int sysctl_extfrag_threshold; extern int sysctl_compact_unevictable_allowed; diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 62fbd09..ceb5c61 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2862,6 +2862,13 @@ static struct ctl_table vm_table[] = { .proc_handler = sysctl_compaction_handler, }, { + .procname = "proactive_compact_memory", + .data = &sysctl_proactive_compact_memory, + .maxlen = sizeof(int), + .mode = 0200, + .proc_handler = sysctl_proactive_compaction_handler, + }, + { .procname = "compaction_proactiveness", .data = &sysctl_compaction_proactiveness, .maxlen = sizeof(sysctl_compaction_proactiveness), diff --git a/mm/compaction.c b/mm/compaction.c index e04f447..2b40b03 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2588,13 +2588,13 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order, * due to various back-off conditions, such as, contention on per-node or * per-zone locks. */ -static void proactive_compact_node(pg_data_t *pgdat) +static void proactive_compact_node(pg_data_t *pgdat, enum migrate_mode mode) { int zoneid; struct zone *zone; struct compact_control cc = { .order = -1, - .mode = MIGRATE_SYNC_LIGHT, + .mode = mode, .ignore_skip_hint = true, .whole_zone = true, .gfp_mask = GFP_KERNEL, @@ -2657,6 +2657,17 @@ static void compact_nodes(void) compact_node(nid); } +static void proactive_compact_nodes(void) +{ + int nid; + + /* Flush pending updates to the LRU lists */ + lru_add_drain_all(); + for_each_online_node(nid) + proactive_compact_node(NODE_DATA(nid), MIGRATE_SYNC); +} + +int sysctl_proactive_compact_memory; /* The written value is actually unused, all memory is compacted */ int sysctl_compact_memory; @@ -2680,6 +2691,14 @@ int sysctl_compaction_handler(struct ctl_table *table, int write, return 0; } +int sysctl_proactive_compaction_handler(struct ctl_table *table, int write, + void *buffer, size_t *length, loff_t *ppos) +{ + if (write) + proactive_compact_nodes(); + + return 0; +} #if defined(CONFIG_SYSFS) && defined(CONFIG_NUMA) static ssize_t sysfs_compact_node(struct device *dev, struct device_attribute *attr, @@ -2881,7 +2900,7 @@ static int kcompactd(void *p) continue; } prev_score = fragmentation_score_node(pgdat); - proactive_compact_node(pgdat); + proactive_compact_node(pgdat, MIGRATE_SYNC_LIGHT); score = fragmentation_score_node(pgdat); /* * Defer proactive compaction if the fragmentation