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 56FEFC0015E for ; Wed, 26 Jul 2023 09:31:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E71EC6B0075; Wed, 26 Jul 2023 05:31:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E21426B0078; Wed, 26 Jul 2023 05:31:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC2C56B007B; Wed, 26 Jul 2023 05:31:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id BCB556B0075 for ; Wed, 26 Jul 2023 05:31:46 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6A8AC160B9D for ; Wed, 26 Jul 2023 09:31:46 +0000 (UTC) X-FDA: 81053245812.13.5F4BC58 Received: from out-24.mta0.migadu.com (out-24.mta0.migadu.com [91.218.175.24]) by imf27.hostedemail.com (Postfix) with ESMTP id 6794C40013 for ; Wed, 26 Jul 2023 09:31:44 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BJaw31GH; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf27.hostedemail.com: domain of muchun.song@linux.dev designates 91.218.175.24 as permitted sender) smtp.mailfrom=muchun.song@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690363904; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=C9JATXkXZaN7f0jrXVOoaEMLIPnzZ4EB9BwhBVu88/k=; b=uw9+nHdCuvhQoQeJOohmlswnPPs2PCZQ+hA+rlbkwgc0nOhdxFPGfmj5WFDFDjxxx8uG+r NehKt8XBf1S3cC02hsiSCVZWELPMSVam+37LGG7wrL+j69fsy6Z//5ygUTw/55u1McpQya JYuEvWJFHvmqw7tV+AV/Nk+uIvRy9Js= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BJaw31GH; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf27.hostedemail.com: domain of muchun.song@linux.dev designates 91.218.175.24 as permitted sender) smtp.mailfrom=muchun.song@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690363904; a=rsa-sha256; cv=none; b=12SsPzO44iLizl4fecLc1FDYjjub41m0U/NbD58WOk2bNBREixAj0QzXfK0I4cghc3ZyOn uJGvI6KR82LSookxkg3D41gXVBtEcXf2S7cw5CSCbcl/zu2KwYQDBOCgSLcSilNu5pPUMy mvGb+wMEcywNsuSD9gmKdfcOClhr2Og= Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1690363901; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C9JATXkXZaN7f0jrXVOoaEMLIPnzZ4EB9BwhBVu88/k=; b=BJaw31GHkPVMB5J3bFLk7nCWUXBih3Evut0vs64rGABml16vhPPP+VTCvSpnvcgPtpNdnt lUE24RniQLpCmG5kFgpHNW+1PDmB/qhB9l9vhPT5YKqpl2p08nrVkD19PS1VqQI3/KFSOu LvMc1Yox7zbU5EqPQ+5oAKbHUZVLA0E= MIME-Version: 1.0 Subject: Re: [PATCH v2 43/47] mm: shrinker: add a secondary array for shrinker_info::{map, nr_deferred} X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <20230724094354.90817-44-zhengqi.arch@bytedance.com> Date: Wed, 26 Jul 2023 17:30:53 +0800 Cc: Andrew Morton , david@fromorbit.com, tkhai@ya.ru, Vlastimil Babka , Roman Gushchin , djwong@kernel.org, Christian Brauner , "Paul E. McKenney" , tytso@mit.edu, steven.price@arm.com, cel@kernel.org, Sergey Senozhatsky , yujie.liu@intel.com, Greg KH , LKML , Linux Memory Management List , x86@kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-erofs@lists.ozlabs.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, linux-mtd@lists.infradead.org, rcu@vger.kernel.org, netdev , dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-bcache@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20230724094354.90817-1-zhengqi.arch@bytedance.com> <20230724094354.90817-44-zhengqi.arch@bytedance.com> To: Qi Zheng X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 6794C40013 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: fba5u9ykwxtkhyo7c48w7acj5nau3bmq X-HE-Tag: 1690363904-266394 X-HE-Meta: U2FsdGVkX18Rk5IdxA6KyyMqZLuznt5JmR+OnUZWdZfykYXNwlPkg7CTx1lyjIGW7T8VqYM8qzjvdknaAwHcvaVrEwDBOH1+7f8XACsh5B+KigiLQxQM5FIjfwm0qofo2u7S9PdfC7EuwP5chBpOGzNb14TrdFuAApJA6kIYjMYY57ZNJCKFWOZvCygT/9nFQs1T+vu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000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: > On Jul 24, 2023, at 17:43, Qi Zheng = wrote: >=20 > Currently, we maintain two linear arrays per node per memcg, which are > shrinker_info::map and shrinker_info::nr_deferred. And we need to = resize > them when the shrinker_nr_max is exceeded, that is, allocate a new = array, > and then copy the old array to the new array, and finally free the old > array by RCU. >=20 > For shrinker_info::map, we do set_bit() under the RCU lock, so we may = set > the value into the old map which is about to be freed. This may cause = the > value set to be lost. The current solution is not to copy the old map = when > resizing, but to set all the corresponding bits in the new map to 1. = This > solves the data loss problem, but bring the overhead of more pointless > loops while doing memcg slab shrink. >=20 > For shrinker_info::nr_deferred, we will only modify it under the read = lock > of shrinker_rwsem, so it will not run concurrently with the resizing. = But > after we make memcg slab shrink lockless, there will be the same data = loss > problem as shrinker_info::map, and we can't work around it like the = map. >=20 > For such resizable arrays, the most straightforward idea is to change = it > to xarray, like we did for list_lru [1]. We need to do xa_store() in = the > list_lru_add()-->set_shrinker_bit(), but this will cause memory > allocation, and the list_lru_add() doesn't accept failure. A possible > solution is to pre-allocate, but the location of pre-allocation is not > well determined. >=20 > Therefore, this commit chooses to introduce a secondary array for > shrinker_info::{map, nr_deferred}, so that we only need to copy this > secondary array every time the size is resized. Then even if we get = the > old secondary array under the RCU lock, the found map and nr_deferred = are > also true, so no data is lost. >=20 > [1]. = https://lore.kernel.org/all/20220228122126.37293-13-songmuchun@bytedance.c= om/ >=20 > Signed-off-by: Qi Zheng Reviewed-by: Muchun Song