From mboxrd@z Thu Jan 1 00:00:00 1970 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=-0.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 77FF8C433E1 for ; Fri, 5 Jun 2020 22:05:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 20D352065C for ; Fri, 5 Jun 2020 22:05:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="X+1JcSe1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 20D352065C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8D35D280001; Fri, 5 Jun 2020 18:05:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8848E8E0006; Fri, 5 Jun 2020 18:05:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77338280001; Fri, 5 Jun 2020 18:05:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0189.hostedemail.com [216.40.44.189]) by kanga.kvack.org (Postfix) with ESMTP id 5D1F78E0006 for ; Fri, 5 Jun 2020 18:05:52 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1F5343745 for ; Fri, 5 Jun 2020 22:05:52 +0000 (UTC) X-FDA: 76896541344.23.stamp65_040c7e326da3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id D91AC3760C for ; Fri, 5 Jun 2020 22:05:51 +0000 (UTC) X-HE-Tag: stamp65_040c7e326da3 X-Filterd-Recvd-Size: 6214 Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Fri, 5 Jun 2020 22:05:51 +0000 (UTC) Received: by mail-ej1-f67.google.com with SMTP id y13so11723523eju.2 for ; Fri, 05 Jun 2020 15:05:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4f2rdGGtN0GdTt9TdrQV5swgjUs+uNX78VGk5PqhDq0=; b=X+1JcSe1mzZv+JApwt8xnJpPUibiJBVICxz3EvKfLWyQRjTAYU6MhWSV2ULjQ/KsfG mhbUPvHUIEMAaWhiKXNaWNCI0bei7OYeYeRiEwAmsVW34upMyy3LdJ01FgIy5zmFNkAV wFYGQJa140sC3KHXGUnnMOZhKOW7qdW9F7gxbfPa58B+Nj+fkXqiW0RRydvx1tF0/ShX BzfyAQuEVpX9hswye5BMFtykNHCjYgMeHacKZI+gnvIAqcdFa2w3LPa38RlRcc3QiwrL +OP/C5MuWOi+jnVF4wZto0iA3XT9V3mDYjkHhsG7Hw5JP2Klg8A2sV5S9bGnngcKf7hs YWFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4f2rdGGtN0GdTt9TdrQV5swgjUs+uNX78VGk5PqhDq0=; b=HfZkYMksN5ko5oB2ut+HGbsKAQVxOogO9K9JcVoAk7w6nQcZUF9Gs5XUG/OL9eyJ3s UMLkqkNvMQE4TRN6DdRGCsZAwUiJetc0VZumI9SxQ6esrEP+IGSmKVffJGa0Mh1ZLUB4 xbmPQTPqWIAGQ2pCXJsVfcXKfFHtd2cixzBxMCMrXZWR9lg4iLDoW72+YJ/GV4jQZVyN F7sowUag/ALLRqnlvTiGcC/Dp6DoOYieX4lr1nF8A54pmcIJCQZ3nXSq7K23/H3CkSkw OCIMecSGLfloMIDkmnZjLlmAjpgqX7+/Y2d4Zq+wpkj4TZGcu6ANlUKAmz3rcLPqtqhn hYbg== X-Gm-Message-State: AOAM530+4J4/UnwLYzfJ1kpLLVXssnmMEYGz+xAqOWrdoJilK/vu6Knm q4LeU25tcvh5y53qtD+oUQ1sJJS7eB3y7D5xpoY= X-Google-Smtp-Source: ABdhPJx0dvE7wkkiwQjrYiP1Jwh+Vekc7J7SHcXZpU27A/ESoitKKr80KD3XhNSjydSLiu+NqY0EFtYd8PrId2ukjag= X-Received: by 2002:a17:906:ae85:: with SMTP id md5mr10688752ejb.213.1591394750297; Fri, 05 Jun 2020 15:05:50 -0700 (PDT) MIME-Version: 1.0 References: <20200601032204.124624-1-gthelen@google.com> In-Reply-To: From: Yang Shi Date: Fri, 5 Jun 2020 15:05:16 -0700 Message-ID: Subject: Re: [PATCH] shmem, memcg: enable memcg aware shrinker To: Greg Thelen Cc: Hugh Dickins , Andrew Morton , Kirill Tkhai , Linux MM , Linux Kernel Mailing List , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: D91AC3760C X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: On Thu, Jun 4, 2020 at 1:17 AM Greg Thelen wrote: > > Yang Shi wrote: > > > On Sun, May 31, 2020 at 8:22 PM Greg Thelen wrote: > >> > >> Since v4.19 commit b0dedc49a2da ("mm/vmscan.c: iterate only over charged > >> shrinkers during memcg shrink_slab()") a memcg aware shrinker is only > >> called when the per-memcg per-node shrinker_map indicates that the > >> shrinker may have objects to release to the memcg and node. > >> > >> shmem_unused_huge_count and shmem_unused_huge_scan support the per-tmpfs > >> shrinker which advertises per memcg and numa awareness. The shmem > >> shrinker releases memory by splitting hugepages that extend beyond > >> i_size. > >> > >> Shmem does not currently set bits in shrinker_map. So, starting with > >> b0dedc49a2da, memcg reclaim avoids calling the shmem shrinker under > >> pressure. This leads to undeserved memcg OOM kills. > >> Example that reliably sees memcg OOM kill in unpatched kernel: > >> FS=/tmp/fs > >> CONTAINER=/cgroup/memory/tmpfs_shrinker > >> mkdir -p $FS > >> mount -t tmpfs -o huge=always nodev $FS > >> # Create 1000 MB container, which shouldn't suffer OOM. > >> mkdir $CONTAINER > >> echo 1000M > $CONTAINER/memory.limit_in_bytes > >> echo $BASHPID >> $CONTAINER/cgroup.procs > >> # Create 4000 files. Ideally each file uses 4k data page + a little > >> # metadata. Assume 8k total per-file, 32MB (4000*8k) should easily > >> # fit within container's 1000 MB. But if data pages use 2MB > >> # hugepages (due to aggressive huge=always) then files consume 8GB, > >> # which hits memcg 1000 MB limit. > >> for i in {1..4000}; do > >> echo . > $FS/$i > >> done > > > > It looks all the inodes which have tail THP beyond i_size are on one > > single list, then the shrinker actually just splits the first > > nr_to_scan inodes. But since the list is not memcg aware, so it seems > > it may split the THPs which are not charged to the victim memcg and > > the victim memcg still may suffer from pre-mature oom, right? > > Correct. shmem_unused_huge_shrink() is not memcg aware. In response to > memcg pressure it will split the post-i_size tails of nr_to_scan tmpfs > inodes regardless of if they're charged to the under-pressure memcg. > do_shrink_slab() looks like it'll repeatedly call > shmem_unused_huge_shrink(). So it will split tails of many inodes. So > I think it'll avoid the oom by over shrinking. This is not ideal. But > it seems better than undeserved oom kill. > > I think the solution (as Kirill Tkhai suggested) a memcg-aware index > would solve both: > 1) avoid premature oom by registering shrinker to responding to memcg > pressure > 2) avoid shrinking/splitting inodes unrelated to the under-pressure > memcg I do agree with Kirill. Using list_lru sounds optimal. But, it looks the memcg index is tricky. The index of memcg which the beyond i_size THP is charged to should be used instead of the inode's memcg which may charge to different memcg. > > I can certainly look into that (thanks Kirill for the pointers). In the > short term I'm still interested in avoiding premature OOMs with the > original thread (i.e. restore pre-4.19 behavior to shmem shrinker for > memcg pressure). I plan to test and repost v2.