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 C9F4CC4332F for ; Mon, 21 Nov 2022 14:38:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DCF26B0071; Mon, 21 Nov 2022 09:38:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 48DAB6B0073; Mon, 21 Nov 2022 09:38:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 32FF16B0074; Mon, 21 Nov 2022 09:38:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 24C8A6B0071 for ; Mon, 21 Nov 2022 09:38:21 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id F1F7F1C60BB for ; Mon, 21 Nov 2022 14:38:20 +0000 (UTC) X-FDA: 80157704760.17.0A29A4F Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf03.hostedemail.com (Postfix) with ESMTP id 59AA02000D for ; Mon, 21 Nov 2022 14:38:20 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BA05322102; Mon, 21 Nov 2022 14:38:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1669041498; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=mGOXq9FRamV9l5/TyyRIyRTXW3ke43JzevqLuofDH3Y=; b=Qp2QXy9NNTrYv3zdpSBl0EZsKd2ZL4OlKqi1kbMro7WI8hKQmgvUkR5L5vMjAFNaRoKLll 28zbJVicyhWSeXLfFhwMz7vyyC3ls5CZwNNI49b0di3gjRKWTlcRmEloPow04B6nT11aGG twcB4xQMvDzPaA2kU7Qi82sGddWVsp4= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8B7351377F; Mon, 21 Nov 2022 14:38:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 7T40H1qNe2PBIgAAMHmgww (envelope-from ); Mon, 21 Nov 2022 14:38:18 +0000 Date: Mon, 21 Nov 2022 15:38:17 +0100 From: Michal Hocko To: Zhongkun He Cc: Andrew Morton , corbet@lwn.net, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org Subject: Re: [External] Re: [PATCH v2] mm: add new syscall pidfd_set_mempolicy(). Message-ID: References: <20221111084051.2121029-1-hezhongkun.hzk@bytedance.com> <20221111112732.30e1696bcd0d5b711c188a9a@linux-foundation.org> <3a3b4f5b-14d1-27d8-7727-cf23da90988f@bytedance.com> <82c9c89c-aee2-08a3-e562-359631bb0137@bytedance.com> <0bd0b744-3d97-b4c3-a4fb-6040f8f8024a@bytedance.com> <6433156f-34a8-400f-e282-91268b242279@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6433156f-34a8-400f-e282-91268b242279@bytedance.com> ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=Qp2QXy9N; spf=pass (imf03.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669041500; a=rsa-sha256; cv=none; b=pzaasBV+nl8nOV16PkzzY4YQ5E7kEZglTsQTps0wH/ok43V9f+Wzs1OKWvNQJWcl/an7eu Kj6LRrtwCq1GnLvduoGOFQfj+I8uugG870sc0egteswZxo1TZfkjeIVdAufWQ6Xo2NFvs0 DjKHYBDjomagP2ru7VdNurldJBFMP6g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669041500; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mGOXq9FRamV9l5/TyyRIyRTXW3ke43JzevqLuofDH3Y=; b=z2otv5OP8Cyya5rmGrmWTHm8ZPhZa9ySvSQlBBE6luRRWUYErLiq8D4rX00IDFintFGdKO R8OyrTzJzQ8PT/3ssrueeETfIocjNUJjaYqqMg+lsY4bck6Dtw37qztKlWyDdmMxg/8SYr dRkOxOwwVMvvKvRirz1P/VY3RER2ofM= X-Rspamd-Queue-Id: 59AA02000D X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=Qp2QXy9N; spf=pass (imf03.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com X-Rspamd-Server: rspam06 X-Stat-Signature: 36upnxa8bmk9ujhmdneoo71rntcpsczr X-HE-Tag: 1669041500-103294 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 17-11-22 15:19:20, Zhongkun He wrote: > Hi Michal, thanks for your replay. > > > > > It would be better to add the patch that has been tested. > > OK. > > > > > One way to deal with that would be to use a similar model as css_tryget > > Percpu_ref is a good way to reduce memory footprint in fast path.But it > has the potential to make mempolicy heavy. the sizeof mempolicy is 32 > bytes and it may not have a long life time, which duplicated from the > parent in fork().If we modify atomic_t to percpu_ref, the efficiency of > reading in fastpath will increase, the efficiency of creation and > deletion will decrease, and the occupied space will increase > significantly.I am not really sure it is worth it. > > atomic_t; 4 > sizeof(percpu_ref + percpu_ref_data + cpus* unsigned long) > 16+56+cpus*8 Yes the memory consumption is going to increase but the question is whether this is something that is a real problem. Is it really common to have many vmas with a dedicated policy? What I am arguing here is that there are essentially 2 ways forward. Either we continue to build up on top of the existing and arguably very fragile code and make it even more subtle or follow a general pattern of a proper reference counting (with usual tricks to reduce cache line bouncing and similar issues). I do not really see why memory policies should be any different and require very special treatment. > > Btw. have you tried to profile those slowdowns to identify hotspots? > > > > Thanks > > Yes, it will degrade performance about 2%-%3 may because of the task_lock > and atomic operations on the reference count as shown > in the previous email. > > new hotspots in perf. > 1.34% [kernel] [k] __mpol_put > 0.53% [kernel] [k] _raw_spin_lock > 0.44% [kernel] [k] get_task_policy Thanks! -- Michal Hocko SUSE Labs