From patchwork Mon Oct 5 08:13:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 11816225 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 90ABF112E for ; Mon, 5 Oct 2020 08:14:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3D27C20781 for ; Mon, 5 Oct 2020 08:14:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D27C20781 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C9CDA6B0062; Mon, 5 Oct 2020 04:14:31 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BFFE16B0068; Mon, 5 Oct 2020 04:14:31 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7B048E0001; Mon, 5 Oct 2020 04:14:31 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0088.hostedemail.com [216.40.44.88]) by kanga.kvack.org (Postfix) with ESMTP id 72B666B0062 for ; Mon, 5 Oct 2020 04:14:31 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 011B71EE6 for ; Mon, 5 Oct 2020 08:14:31 +0000 (UTC) X-FDA: 77337159942.28.story94_0616ccc271bc Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id CE8736C05 for ; Mon, 5 Oct 2020 08:14:30 +0000 (UTC) X-Spam-Summary: 1,0,0,ce4cfe0024503abb,d41d8cd98f00b204,andrea.righi@canonical.com,,RULES_HIT:41:355:379:541:800:960:966:968:973:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1542:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2559:2562:2693:2731:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3871:4321:4385:4605:5007:6119:6120:6261:7901:7903:10004:11026:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:12986:13141:13230:13894:14096:14181:14394:14721:14819:21060:21080:21444:21451:21627:21990:30034:30054,0,RBL:91.189.89.112:@canonical.com:.lbl8.mailshell.net-62.8.15.100 64.201.201.201;04y8jdyo8kt3nres5aq9qpnwtcdo7occ79zrddakg474kpd977kutw6o4zhxnu7.npdmc5pi87dq47b6xk7gd7o36migitgm7w61p6393s8xm3dxi5egxizxj33qmp1.4-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: story94_0616ccc271bc X-Filterd-Recvd-Size: 5658 Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Mon, 5 Oct 2020 08:14:30 +0000 (UTC) Received: from mail-wr1-f70.google.com ([209.85.221.70]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kPLdc-0001Hu-Ta for linux-mm@kvack.org; Mon, 05 Oct 2020 08:14:29 +0000 Received: by mail-wr1-f70.google.com with SMTP id 33so1376065wrf.22 for ; Mon, 05 Oct 2020 01:14:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YOOKKc/NsxErESy/u7hg3zhXpqetp++Zy7NLfv5ic88=; b=iGeQITIKNnVxfINr+gyIlPAxWDchJC0LExwxmkmqZoEPlVAqL5PH8o6/0iJUVp9BIS GfK+Bom/4oQo3Wfi+JtJlIonTXPyYhECuHzLEWfov3X3qWThhIRXykgaz/RNSzciXFxP Qb/GqvtFC2Fqplw4XnwJuIS/jyX9PcOu3XSDUVS5WsrBA7/Vo/RRfqAGVUPQ4/IlA6KJ 5Fyx6fMDXFGSrwg0bYrbXKlDh6uXKUDoR5Ann7fIK7zjgaqxCpa5+8jiSy3pCJIXObHq QIFX+QUcJvx53Jg8D/CPyde/ZMBYFJ/VfN7JEwm6+I+ur6LLXgBnFIW/W22z6N++BPEw TWwA== X-Gm-Message-State: AOAM533PTxH72OOgJlDyvz5R6QyKkrQUjiTla4eBBgY5jSo6Nbmzyw/v Oqz7ERthgt1yQ1dngSM2TBUeIfISWLYeXZ2wwNypdBtvk3nhUqKBD2vN7YGHspwwyG+7I/1/xCU kr0V8JqyYrq7rXCQySwKdh7d+J33I X-Received: by 2002:a5d:67d0:: with SMTP id n16mr17497446wrw.198.1601885668390; Mon, 05 Oct 2020 01:14:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtKOpH0FCV6s7xth+z5GIgfZ6KMfLvYYR4CHJf3bHlkFzgc8Y/X0OX+gbrjhuJR5dAK1ORUw== X-Received: by 2002:a5d:67d0:: with SMTP id n16mr17497429wrw.198.1601885668147; Mon, 05 Oct 2020 01:14:28 -0700 (PDT) Received: from xps-13-7390.homenet.telecomitalia.it (host-79-36-133-218.retail.telecomitalia.it. [79.36.133.218]) by smtp.gmail.com with ESMTPSA id a15sm13168855wrn.3.2020.10.05.01.14.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Oct 2020 01:14:27 -0700 (PDT) From: Andrea Righi To: Michal Hocko , Vladimir Davydov Cc: Li Zefan , Tejun Heo , Johannes Weiner , Andrew Morton , Luigi Semenzato , "Rafael J . Wysocki" , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH RFC v2 1/2] mm: memcontrol: make shrink_all_memory() memcg aware Date: Mon, 5 Oct 2020 10:13:12 +0200 Message-Id: <20201005081313.732745-2-andrea.righi@canonical.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005081313.732745-1-andrea.righi@canonical.com> References: <20201005081313.732745-1-andrea.righi@canonical.com> MIME-Version: 1.0 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: Allow to specify a memcg when calling shrink_all_memory() to reclaim some memory from a specific cgroup. Moreover, make shrink_all_memory() always available and do not depend on having CONFIG_HIBERNATION enabled. This is required by the opportunistic memory reclaim feature. Signed-off-by: Andrea Righi --- include/linux/swap.h | 9 ++++++++- mm/vmscan.c | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 661046994db4..1490b09a6e6c 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -368,7 +368,14 @@ extern unsigned long mem_cgroup_shrink_node(struct mem_cgroup *mem, gfp_t gfp_mask, bool noswap, pg_data_t *pgdat, unsigned long *nr_scanned); -extern unsigned long shrink_all_memory(unsigned long nr_pages); +extern unsigned long +__shrink_all_memory(unsigned long nr_pages, struct mem_cgroup *memcg); + +static inline unsigned long shrink_all_memory(unsigned long nr_pages) +{ + return __shrink_all_memory(nr_pages, NULL); +} + extern int vm_swappiness; extern int remove_mapping(struct address_space *mapping, struct page *page); diff --git a/mm/vmscan.c b/mm/vmscan.c index 466fc3144fff..ac04d5e16c42 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3986,7 +3986,6 @@ void wakeup_kswapd(struct zone *zone, gfp_t gfp_flags, int order, wake_up_interruptible(&pgdat->kswapd_wait); } -#ifdef CONFIG_HIBERNATION /* * Try to free `nr_to_reclaim' of memory, system-wide, and return the number of * freed pages. @@ -3995,7 +3994,8 @@ void wakeup_kswapd(struct zone *zone, gfp_t gfp_flags, int order, * LRU order by reclaiming preferentially * inactive > active > active referenced > active mapped */ -unsigned long shrink_all_memory(unsigned long nr_to_reclaim) +unsigned long +__shrink_all_memory(unsigned long nr_to_reclaim, struct mem_cgroup *memcg) { struct scan_control sc = { .nr_to_reclaim = nr_to_reclaim, @@ -4006,6 +4006,7 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim) .may_unmap = 1, .may_swap = 1, .hibernation_mode = 1, + .target_mem_cgroup = memcg, }; struct zonelist *zonelist = node_zonelist(numa_node_id(), sc.gfp_mask); unsigned long nr_reclaimed; @@ -4023,7 +4024,6 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim) return nr_reclaimed; } -#endif /* CONFIG_HIBERNATION */ /* * This kswapd start function will be called by init and node-hot-add.