From patchwork Tue Oct 22 20:15:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 11205329 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 D56B113B1 for ; Tue, 22 Oct 2019 20:15:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A1F7521783 for ; Tue, 22 Oct 2019 20:15:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="G6GQH0AR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A1F7521783 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D413A6B0003; Tue, 22 Oct 2019 16:15:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CF3086B0006; Tue, 22 Oct 2019 16:15:21 -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 BBE1C6B0007; Tue, 22 Oct 2019 16:15:21 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0192.hostedemail.com [216.40.44.192]) by kanga.kvack.org (Postfix) with ESMTP id 9A35E6B0003 for ; Tue, 22 Oct 2019 16:15:21 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 1E591180AD80F for ; Tue, 22 Oct 2019 20:15:21 +0000 (UTC) X-FDA: 76072525242.15.hair79_2ea0304d2a627 X-Spam-Summary: 2,0,0,0a6dd7305e4ac190,d41d8cd98f00b204,hannes@cmpxchg.org,:akpm@linux-foundation.org:mhocko@suse.com::cgroups@vger.kernel.org:linux-kernel@vger.kernel.org:kernel-team@fb.com,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1437:1515:1534:1539:1711:1714:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3351:3865:3866:3867:3870:3871:4321:5007:6261:6653:10004:11026:11658:11914:12297:12517:12519:12555:12895:13069:13311:13357:13894:14096:14181:14384:14394:14721:21080:21444:21451:21627:30012:30054,0,RBL:209.85.222.194:@cmpxchg.org:.lbl8.mailshell.net-62.14.0.100 66.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: hair79_2ea0304d2a627 X-Filterd-Recvd-Size: 3597 Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Oct 2019 20:15:20 +0000 (UTC) Received: by mail-qk1-f194.google.com with SMTP id a194so13477616qkg.10 for ; Tue, 22 Oct 2019 13:15:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/6k43Ins8ShDUccC1LdBvMXrfhZMN86K2kUQuaiv7Mo=; b=G6GQH0AR0jPSft2ppe6Krr/rZ5GlNjjcDjh8uq21Mch7IOkfMJPJ6y8CGYHqjeZnRv Z82dyGlkUmpnrQUBDNlEbomTWJFZjTonGAtP+KWs1/C1lYr5lpWixX5fS4x8g1/pnjaI l+2sZb8+h8PVY95WqVGA2Z3wHkTZ5GJmzwN6p8slt1PJfa3X9acHSQ9TwJh6O9hoz8yK QoDS9inHtGfOdYETaFcmImy68omaIjrSwXUv00ynL3dDOGxlMHQeZN4xH1DKUj15Seb/ 4B+CZLYcbnEkE5LYhr+FWPasz/NfM9n5wmSZzFIvbKNULO+4fsvtj9SnmUeuv1klLi0C eunw== 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:mime-version :content-transfer-encoding; bh=/6k43Ins8ShDUccC1LdBvMXrfhZMN86K2kUQuaiv7Mo=; b=GyS1010m8AM+LYXDdRzcAUbcN4q6cdgbjCSmvAUCAl1bfa/TJrmEMG4EYKKQcNaWQO FL3BnMzBn+v18JI+kVjsI44bQmE+hPDOEvrIK+JXy8rHOWrcYaChi3dnq0KVhQ9g8Cif g4ok1nROnnWQ+WNdOoXlqc0AuozWeg3pJl1F1ANLTFdDEgEmyMUYkIRWpx3qR3Km1Fr+ vodk/5kd4FzKPgXUdj5xUnLGSkTc4SEyQ6t4gScUoEsoW2JF5/W8U8YhALQ3rqlenKyP GI0evBVq6LIx7iPUu6X+1syy3ULaZRTmbu2ex3tkVkDkRdh9Njtr5QsH5H1Dq2r0yRZo gXpw== X-Gm-Message-State: APjAAAXuXCAzTeaDFIaF395uzfCIX9KDzomVCPAI9Hrn/6hYtMP9BBSp xdPDvy0KHyWoCj8qBfSW2dn9DQ== X-Google-Smtp-Source: APXvYqwf83Q3oMgxGQXXVkIgEXOw8vw6FhbO2OSQt0mKSX9kQGxr6dmirL8tHiP1nzutNQLLmqtnhw== X-Received: by 2002:a37:f70f:: with SMTP id q15mr4521717qkj.428.1571775319334; Tue, 22 Oct 2019 13:15:19 -0700 (PDT) Received: from localhost ([2620:10d:c091:500::3:869e]) by smtp.gmail.com with ESMTPSA id d205sm11273855qke.96.2019.10.22.13.15.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2019 13:15:18 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Michal Hocko , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 1/2] mm: memcontrol: remove dead code from memory_max_write() Date: Tue, 22 Oct 2019 16:15:17 -0400 Message-Id: <20191022201518.341216-1-hannes@cmpxchg.org> X-Mailer: git-send-email 2.23.0 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: When the reclaim loop in memory_max_write() is ^C'd or similar, we set err to -EINTR. But we don't return err. Once the limit is set, we always return success (nbytes). Delete the dead code. Signed-off-by: Johannes Weiner Acked-by: Michal Hocko --- mm/memcontrol.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 055975b0b3a3..ff90d4e7df37 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6122,10 +6122,8 @@ static ssize_t memory_max_write(struct kernfs_open_file *of, if (nr_pages <= max) break; - if (signal_pending(current)) { - err = -EINTR; + if (signal_pending(current)) break; - } if (!drained) { drain_all_stock(memcg); From patchwork Tue Oct 22 20:15:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 11205331 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 5773413B1 for ; Tue, 22 Oct 2019 20:15:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2488521783 for ; Tue, 22 Oct 2019 20:15:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="KaaLg/bw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2488521783 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B6DD06B0006; Tue, 22 Oct 2019 16:15:22 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AF8236B0007; Tue, 22 Oct 2019 16:15:22 -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 924D56B0008; Tue, 22 Oct 2019 16:15:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0104.hostedemail.com [216.40.44.104]) by kanga.kvack.org (Postfix) with ESMTP id 64B4B6B0006 for ; Tue, 22 Oct 2019 16:15:22 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id C2E5F7582 for ; Tue, 22 Oct 2019 20:15:21 +0000 (UTC) X-FDA: 76072525242.10.robin02_2ec6923a3f33a X-Spam-Summary: 2,0,0,12016adaf7b38910,d41d8cd98f00b204,hannes@cmpxchg.org,:akpm@linux-foundation.org:mhocko@suse.com::cgroups@vger.kernel.org:linux-kernel@vger.kernel.org:kernel-team@fb.com,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1542:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2689:2898:3138:3139:3140:3141:3142:3354:3865:3866:3867:3870:3871:3874:4250:4321:4385:5007:6119:6120:6261:6653:7875:7901:7903:8531:8603:8660:10004:11026:11233:11473:11658:11914:12043:12291:12295:12296:12297:12438:12517:12519:12555:12664:12683:12895:12986:13148:13184:13229:13230:13894:14096:14181:14394:14721:21080:21444:21451:21627:21740:21795:30051:30054:30070,0,RBL:209.85.160.193:@cmpxchg.org:.lbl8.mailshell.net-62.14.0.100 66.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: robin02_2ec6923a3f33a X-Filterd-Recvd-Size: 5723 Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Oct 2019 20:15:21 +0000 (UTC) Received: by mail-qt1-f193.google.com with SMTP id z22so8255795qtq.11 for ; Tue, 22 Oct 2019 13:15:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SKH3PcY5YzXD6Qge68ymWg6Ins6ocLR9l5DfPryEBgk=; b=KaaLg/bw88z77buICYAJEe5iw5ThIZJCDvLL4q2RSdmGOXSdlsryIy4UAPdKiR3U1i TnF8jNwIgRKrMzBMH2cBT8Qyy9tg/M9wTtR3Wrx6e/JrVGOp77QhbBjRArE2l/meQdby SOdO/mGWcTubS8kR90ln5IenSVxDk0WPTvDqpdaDO4iRAPQXIssKgsKkCTzxFI7D99tI K/w9BneoewwmdaDHDt5q8QWenhYLUUAhYRi0GJm58lfdROEHZrbuhSNsUmJ7vhrTLZoB TlgRns9OFeILnr1C45VJ/hBfpRmLpXl6WY6/23dwwSlktV02dZHRpDlk39xE/9wyzzJf OKPw== 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=SKH3PcY5YzXD6Qge68ymWg6Ins6ocLR9l5DfPryEBgk=; b=eBKKBj68ewHoFVq0TE688Nv9m3nODcqnhzzpK8P1jr/TOSBz3PPKWyK+p9XQvcMYYR 06H9Xbl2hLPsSLYje9aCVGRMf/cyDKyoTAYBbeltqnl54HM5iZLW/Bs/BEf9v8ffBcHE +vMvBOhakUzRVxQE5Df69XlOJhBdAosMN0zINRcbnFsWR8iuKN/7v/4iwM2l1IAR42G9 /4TFkHWTB8E8l7nVdjkI6p8zHFYKTl3fQPbcrOqPEwTSMqxfyjx2ioEebyZi9uiNYoMD RMO5fu1gK8/mpIYISrWFBzw0fXOT16aR9naSTBaHaDsmqzrlWG3eUrhOjcGVK7+wckL7 Bhnw== X-Gm-Message-State: APjAAAWmizNxPuVzZoxeNfjr6ac7OUsdYkNx7Ps5kX9qgVspknckW+uI XFkHZTVjJB97mBbVLTmgbWBrFA== X-Google-Smtp-Source: APXvYqwgUaBUtrSrtIlAxyDVz2P4+gAp3Nwe5EnwHYyjxxj2PszLHekWjQXPyQk3tbOPUN9yPnbdVQ== X-Received: by 2002:a0c:d0e1:: with SMTP id b30mr5126174qvh.197.1571775320721; Tue, 22 Oct 2019 13:15:20 -0700 (PDT) Received: from localhost ([2620:10d:c091:500::3:869e]) by smtp.gmail.com with ESMTPSA id e15sm7759814qkm.130.2019.10.22.13.15.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2019 13:15:20 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Michal Hocko , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 2/2] mm: memcontrol: try harder to set a new memory.high Date: Tue, 22 Oct 2019 16:15:18 -0400 Message-Id: <20191022201518.341216-2-hannes@cmpxchg.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191022201518.341216-1-hannes@cmpxchg.org> References: <20191022201518.341216-1-hannes@cmpxchg.org> 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: Setting a memory.high limit below the usage makes almost no effort to shrink the cgroup to the new target size. While memory.high is a "soft" limit that isn't supposed to cause OOM situations, we should still try harder to meet a user request through persistent reclaim. For example, after setting a 10M memory.high on an 800M cgroup full of file cache, the usage shrinks to about 350M: + cat /cgroup/workingset/memory.current 841568256 + echo 10M + cat /cgroup/workingset/memory.current 355729408 This isn't exactly what the user would expect to happen. Setting the value a few more times eventually whittles the usage down to what we are asking for: + echo 10M + cat /cgroup/workingset/memory.current 104181760 + echo 10M + cat /cgroup/workingset/memory.current 31801344 + echo 10M + cat /cgroup/workingset/memory.current 10440704 To improve this, add reclaim retry loops to the memory.high write() callback, similar to what we do for memory.max, to make a reasonable effort that the usage meets the requested size after the call returns. Afterwards, a single write() to memory.high is enough in all but extreme cases: + cat /cgroup/workingset/memory.current 841609216 + echo 10M + cat /cgroup/workingset/memory.current 10182656 Signed-off-by: Johannes Weiner Acked-by: Michal Hocko --- mm/memcontrol.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index ff90d4e7df37..8090b4c99ac7 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6074,7 +6074,8 @@ static ssize_t memory_high_write(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of)); - unsigned long nr_pages; + unsigned int nr_retries = MEM_CGROUP_RECLAIM_RETRIES; + bool drained = false; unsigned long high; int err; @@ -6085,12 +6086,29 @@ static ssize_t memory_high_write(struct kernfs_open_file *of, memcg->high = high; - nr_pages = page_counter_read(&memcg->memory); - if (nr_pages > high) - try_to_free_mem_cgroup_pages(memcg, nr_pages - high, - GFP_KERNEL, true); + for (;;) { + unsigned long nr_pages = page_counter_read(&memcg->memory); + unsigned long reclaimed; + + if (nr_pages <= high) + break; + + if (signal_pending(current)) + break; + + if (!drained) { + drain_all_stock(memcg); + drained = true; + continue; + } + + reclaimed = try_to_free_mem_cgroup_pages(memcg, nr_pages - high, + GFP_KERNEL, true); + + if (!reclaimed && !nr_retries--) + break; + } - memcg_wb_domain_size_changed(memcg); return nbytes; }