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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C750C433F5 for ; Mon, 6 Dec 2021 23:34:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EEFC96B0085; Mon, 6 Dec 2021 18:34:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E9F6A6B0087; Mon, 6 Dec 2021 18:34:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D40AA6B0088; Mon, 6 Dec 2021 18:34:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay036.a.hostedemail.com [64.99.140.36]) by kanga.kvack.org (Postfix) with ESMTP id C03BD6B0085 for ; Mon, 6 Dec 2021 18:34:33 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 746A620B58 for ; Mon, 6 Dec 2021 23:34:23 +0000 (UTC) X-FDA: 78888975606.01.D9FCFDA Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf29.hostedemail.com (Postfix) with ESMTP id 0F0079000094 for ; Mon, 6 Dec 2021 23:34:22 +0000 (UTC) Received: by mail-pl1-f181.google.com with SMTP id m24so8107261pls.10 for ; Mon, 06 Dec 2021 15:34:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=p8EW1Ac6IzpAeuuHrkE2OKk7Spc6Hw56mWD40d+uSE8=; b=Hn7ft3bHGqdFcYx037N7qCj/mnnzh0pf81Bmim2KDg4gIfTADuPGC7YwsAqq0asjpu 8cGCAErt8FmjnZ+o/yyThMjIMUNizmxHDzy1l3mGJFiSSwnXLVYRatiU4IDHuPdmdOsG wCTkxsbu8TeyLKh1Bcs4ges3KMhafYuXsLzGzscjuBAxJ89TR/SrY+KyB94W669YSqbk ajP9d5/48cpEPuVEJmQJQy7y/QLBzHmkJT3Lm/D+jZg21cTzTJ4EP2VZ5sCLH9C9tV16 QmJgU0tr2XaBZSzazbCAFysujmtCHqJQsSxwpBq5XyKxW2mtRV8jLs4JqvZh0iiSf58Q OYEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=p8EW1Ac6IzpAeuuHrkE2OKk7Spc6Hw56mWD40d+uSE8=; b=Dyn+JnS2zQytCHg2MdQsl88/iaiswy4Tlemnu8Z5aCfek0Mm7qQrgCMJKVz7Z1NvhD /OH1wlwbxnySqAh+5JgLBARgGf++h6DLShXSdjHlJz+tC2qFu6nSyJ9JrhrEZuCpR+M/ 1PeFzpu+vmOqQBOXsWDahA7L8JKs+ZPcibsm3/IZ3UVd33M7tfpdvAjm9mf5IHvKUxhW sw49C8M055eCHO7kh0C1iZgL4YBbG+nByz4EKEhaoxvqOG6f9RXUEoAILjdkdvwRdb/3 gNkPxbJ1HDgTviaPbbKnRZkXaD9w/8zRZ30SY2l5TmoFYFi2bBdTlVm7gf++2nqz1qqM ClPw== X-Gm-Message-State: AOAM531hSDjGSe03nMLoyaIdZrfksvvP6I3MzreTHNKj0CqEXUXTF6Kz J4w1GeTvAjy4Yjuz6xtFSMs= X-Google-Smtp-Source: ABdhPJyv+ENk2j94NlhoLFkMFT4av9j5znmw0xgAcTBizJCNYfWANaRZRDXauJnqUIOTXgCLuoz78A== X-Received: by 2002:a17:90b:3144:: with SMTP id ip4mr2090680pjb.153.1638833661859; Mon, 06 Dec 2021 15:34:21 -0800 (PST) Received: from google.com ([2620:15c:211:201:2d37:bc7d:9c01:7721]) by smtp.gmail.com with ESMTPSA id d6sm10770471pgv.48.2021.12.06.15.34.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 15:34:21 -0800 (PST) Date: Mon, 6 Dec 2021 15:34:19 -0800 From: Minchan Kim To: Andrew Morton Cc: Michal Hocko , David Hildenbrand , linux-mm , LKML , Suren Baghdasaryan , John Dias Subject: Re: [PATCH] mm: don't call lru draining in the nested lru_cache_disable Message-ID: References: <20211206221006.946661-1-minchan@kernel.org> <20211206150421.fc06972fac949a5f6bc8b725@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211206150421.fc06972fac949a5f6bc8b725@linux-foundation.org> X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 0F0079000094 X-Stat-Signature: s1ma1r66m3wtdgsohuasiatz3n5pp7nw Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Hn7ft3bH; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=pass (imf29.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=minchan.kim@gmail.com X-HE-Tag: 1638833662-83144 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 Mon, Dec 06, 2021 at 03:04:21PM -0800, Andrew Morton wrote: > On Mon, 6 Dec 2021 14:10:06 -0800 Minchan Kim wrote: > > > lru_cache_disable involves IPIs to drain pagevec of each core, > > which sometimes takes quite long time to complete depending > > on cpu's business, which makes allocation too slow up to > > sveral hundredth milliseconds. Furthermore, the repeated draining > > in the alloc_contig_range makes thing worse considering caller > > of alloc_contig_range usually tries multiple times in the loop. > > > > This patch makes the lru_cache_disable aware of the fact the > > pagevec was already disabled. With that, user of alloc_contig_range > > can disable the lru cache in advance in their context during the > > repeated trial so they can avoid the multiple costly draining > > in cma allocation. > > Isn't this racy? > > > ... > > > > @@ -859,7 +869,12 @@ atomic_t lru_disable_count = ATOMIC_INIT(0); > > */ > > void lru_cache_disable(void) > > { > > - atomic_inc(&lru_disable_count); > > + /* > > + * If someone is already disabled lru_cache, just return with > > + * increasing the lru_disable_count. > > + */ > > + if (atomic_inc_not_zero(&lru_disable_count)) > > + return; > > #ifdef CONFIG_SMP > > /* > > * lru_add_drain_all in the force mode will schedule draining on > > @@ -873,6 +888,7 @@ void lru_cache_disable(void) > > #else > > lru_add_and_bh_lrus_drain(); > > #endif > > There's a window here where lru_disable_count==0 and new pages can get > added to lru? Indeed. If __lru_add_drain_all in core A didn't run yet but increased the disable count already, lru_cache_disable in core B will not see those pages in the LRU. Need to be fixed it. Thanks, Andrew.