Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2399918pxb; Thu, 11 Feb 2021 11:18:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbmLYzvJJSetKZwh8cp8CUceOAeRVsjBTEDc9kufBlXfWgXUg6nxObWnGe9pl+XVFljZ3J X-Received: by 2002:a17:906:d18e:: with SMTP id c14mr10078059ejz.302.1613071105623; Thu, 11 Feb 2021 11:18:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613071105; cv=none; d=google.com; s=arc-20160816; b=y0ZdPoS/QXy3i68/WsqXHm2CspA/7Zr8g+JxcZ7icPKBiNRk9lVUC27JGCY8aXynvi hLc+BIwzGiHWGMH1MPiI2DfJVpfe7+UwMhR8X76er2umKNQitjZo3uB3BkwigJk+VpdX 2y1u8dXrrAI6mQLiq23MXAEyFqed2exb/+NxNNoXEv8DFMr0hm46Ur5F88UVRBtVnrau smOpTeD/X1lRTeAbtbytdN+YznjVKOm6K6oGkVKGzhJfwc21Ctld90JQJyDPPcL0v6bh Z18uDcfcybnHUgWuGrKmhhWItzH6GPOA1jZ41z+njpjdhz8TU8H0Uyytg+/ieHSdazBI MVCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=6aiFefqoimb6TFhPhRuNGjxw3R3UdnJbDOdGhYcf71E=; b=zvBkRzdBA+yG4nhpEbGZ2gvzjZHwWrqMHKydSSGxm1aPjgWwynfn2WMcOv4M0KmpVy uo4m4A1TvuglIhIbP+wPuqpff3XRGHiDAdhKK0Hzwxl0IJB8Tr6I6d1K4sp3CNm075Dd mE8rJKAiO9j0RCTYDX4M8oaMh2iJCxX9sWOaVjSotMkvS3+so9YN3e7Z3LvSm0RsSUE3 tDUblUNgAu3k7Td84VfW91srfIA498FYjwB3qfzoD/i2cDW6qq0eHgeNxk6nzRbPBVM8 ykSDBbUwftV7njdchpY7AjxNhvpR1xpxIZK+p7m63kQrkqlP/ZoscxaweVI2uGqWpASx Jf2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=u4NieD2D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w23si4353928eju.171.2021.02.11.11.18.01; Thu, 11 Feb 2021 11:18:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=u4NieD2D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230059AbhBKTQG (ORCPT + 99 others); Thu, 11 Feb 2021 14:16:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbhBKTP7 (ORCPT ); Thu, 11 Feb 2021 14:15:59 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44DB3C061574; Thu, 11 Feb 2021 11:15:18 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id l12so8150802edt.3; Thu, 11 Feb 2021 11:15:18 -0800 (PST) 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=6aiFefqoimb6TFhPhRuNGjxw3R3UdnJbDOdGhYcf71E=; b=u4NieD2DpZipPoDbNyb/O29FcpWoDFTEF5fVeUcQTfXHWoLGXlQid9V+apL8Ac0OTx vLPeGmb2H7cO+Zo6GzVfk/aqVX5vNPx0jIYVkSe2EJEB+Cukt7sAd5oVQYnue4RQdxl3 mm0FLTPcAEHNVRdGmF3iVdf0Zt/JbGAjrgO2sinnSWRlbmLxKIUFsvngM6FluQ3YpAhg oNU0SPvRzOPDeY0prhkg3nCXCy6Mfs3smJ6EBXOZ8EIcDKMpNuR9cAnVYAvOcPQ+HheF TiuKKmMbylyQHrRIveNrELq3Nq/oAFkmEAWu4G5VoYHqDXKPymxkbJ1pNEoWlFH04aQM qXxg== 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=6aiFefqoimb6TFhPhRuNGjxw3R3UdnJbDOdGhYcf71E=; b=qerUfV40V6DQ1oz1hPkYGGP8hCY3VlPhB1qk2y5Ed1FIqVBdoPyF51ZaPQSu7J8yXT JMDqgifssf8cC4mbNl/20KJWiOkH7eEBHY+/fof/ybyRbL7FDkC8W6saxJX7/QLgdotm gN69LQHj1zunOafV7K4BfoLEdYR9WKvGq4M+FvCM1dlF4liOu8jXqEG+WzbeKS2gfUcj sy++Gv5+N/bWFvm5qyzFaX0iwoj8kmYADP/SW6PgNB5I2MEinfTdvriGcGIDqH+2N8y0 LkfoK/yx6JQ+dUH382h5VMXtuffpA1pTRsuWm/PqZHM9cUW7rWINgxvh/2MH4BiboyVF oJ1A== X-Gm-Message-State: AOAM533VRYIx8O8HBbYyEasneO0Xl6D6/6gzEZvIqsOpyYK1PrUn7e9X i6UZkhXjgOA8BZMrkUa6Ujnpunfct1RNP3RCCvM= X-Received: by 2002:aa7:de82:: with SMTP id j2mr9740116edv.313.1613070916975; Thu, 11 Feb 2021 11:15:16 -0800 (PST) MIME-Version: 1.0 References: <20210209174646.1310591-1-shy828301@gmail.com> <20210209174646.1310591-13-shy828301@gmail.com> In-Reply-To: From: Yang Shi Date: Thu, 11 Feb 2021 11:15:04 -0800 Message-ID: Subject: Re: [v7 PATCH 12/12] mm: vmscan: shrink deferred objects proportional to priority To: Vlastimil Babka Cc: Roman Gushchin , Kirill Tkhai , Shakeel Butt , Dave Chinner , Johannes Weiner , Michal Hocko , Andrew Morton , Linux MM , Linux FS-devel Mailing List , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 11, 2021 at 10:52 AM Vlastimil Babka wrote: > > On 2/11/21 6:29 PM, Yang Shi wrote: > > On Thu, Feb 11, 2021 at 5:10 AM Vlastimil Babka wrote: > >> > trace_mm_shrink_slab_start(shrinker, shrinkctl, nr, > >> > freeable, delta, total_scan, priority); > >> > @@ -737,10 +708,9 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, > >> > cond_resched(); > >> > } > >> > > >> > - if (next_deferred >= scanned) > >> > - next_deferred -= scanned; > >> > - else > >> > - next_deferred = 0; > >> > + next_deferred = max_t(long, (nr - scanned), 0) + total_scan; > >> > >> And here's the bias I think. Suppose we scanned 0 due to e.g. GFP_NOFS. We count > >> as newly deferred both the "delta" part of total_scan, which is fine, but also > >> the "nr >> priority" part, where we failed to our share of the "reduce > >> nr_deferred" work, but I don't think it means we should also increase > >> nr_deferred by that amount of failed work. > > > > Here "nr" is the saved deferred work since the last scan, "scanned" is > > the scanned work in this round, total_scan is the *unscanned" work > > which is actually "total_scan - scanned" (total_scan is decreased by > > scanned in each loop). So, the logic is "decrease any scanned work > > from deferred then add newly unscanned work to deferred". IIUC this is > > what "deferred" means even before this patch. > > Hm I thought the logic was "increase by any new work (delta) that wasn't done, > decrease by old deferred work that was done now". My examples with scanned = 0 > and scanned = total_work (total_work before subtracting scanned from it) should > demonstrate that the logic is different with your patch. I think we are on the same page about the logic. But I agree the formula implemented in the code is wrong. > > >> OTOH if we succeed and scan exactly the whole goal, we are subtracting from > >> nr_deferred both the "nr >> priority" part, which is correct, but also delta, > >> which was new work, not deferred one, so that's incorrect IMHO as well. > > > > I don't think so. The deferred comes from new work, why not dec new > > work from deferred? > > > > And, the old code did: > > > > if (next_deferred >= scanned) > > next_deferred -= scanned; > > else > > next_deferred = 0; > > > > IIUC, it also decreases the new work (the scanned includes both last > > deferred and new delata). > > Yes, but in the old code, next_deferred starts as > > nr = count_nr_deferred()... > total_scan = nr; > delta = ... // something based on freeable > total_scan += delta; > next_deferred = total_scan; // in the common case total_scan >= 0 > > ... and that's "total_scan" before "scanned" is subtracted from it, so it > includes the new_work ("delta"), so then it's OK to do "next_deferred -= scanned"; > > I still think your formula is (unintentionally) changing the logic. You can also > look at it from different angle, it's effectively (without the max_t() part) "nr > - scanned + total_scan" where total_scan is actually "total_scan - scanned" as > you point your yourself. So "scanned" is subtracted twice? That can't be correct... Yes, I think you are right, it can not be correct. Actually I wanted plus the unscanned delta part to the next_deferred. But my formula actually not only decs scanned twice but also adds unscanned deferred back again. So it seems the formula suggested by you is correct. Will correct this in v8. Thanks a lot for helping get out of the maze. Will add some notes right before the formula as well. > > >> So the calculation should probably be something like this? > >> > >> next_deferred = max_t(long, nr + delta - scanned, 0); > >> > >> Thanks, > >> Vlastimil > >> > >> > + next_deferred = min(next_deferred, (2 * freeable)); > >> > + > >> > /* > >> > * move the unused scan count back into the shrinker in a > >> > * manner that handles concurrent updates. > >> > > >> > > >