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 F38B5C43219 for ; Tue, 15 Nov 2022 07:39:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 094946B0071; Tue, 15 Nov 2022 02:39:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 01E7A6B0072; Tue, 15 Nov 2022 02:39:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD9BF6B0073; Tue, 15 Nov 2022 02:39:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id CB9E36B0071 for ; Tue, 15 Nov 2022 02:39:10 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7E84FC0F90 for ; Tue, 15 Nov 2022 07:39:10 +0000 (UTC) X-FDA: 80134875660.29.D0937C9 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf15.hostedemail.com (Postfix) with ESMTP id 05FFEA000C for ; Tue, 15 Nov 2022 07:39:08 +0000 (UTC) Received: by mail-pf1-f169.google.com with SMTP id g62so13360029pfb.10 for ; Mon, 14 Nov 2022 23:39:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=qrKxYxO/T/9+ij5BpZ+ZeE91vTMifnc8qboFL3OM2PU=; b=H01TrKGhQrD5MzuM4fOKDD5uVKMwHmW0a2HUiqcgBfGdx+x8fahWBZgYIaWZbJeywr fZSutuU7hMyabiDX4PvQFlJRZG/NI9FZMGgbpxMXcpHWRQgP9FTvHDRCoqq5IZfLXjk8 a7kRqownJt+7uXXfEMcRzLwDYxVIQkoCjcgSBODuxOJddjB3/9/SG1h7Qn04lglhLTo6 LWhgRHFBV5vIiK+qSGNXeYd+FJn90lIJOGwqQS7Rgul0LkJYgkXu5mpUSBrvKz7/f5u/ CmLFjD/T9aAY77w4gyCmSRQeaOirfaoTEdXZz6f3GR+InFg4D/xZAGJlWKqqTg77tm1x 39Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=qrKxYxO/T/9+ij5BpZ+ZeE91vTMifnc8qboFL3OM2PU=; b=F0Ro4nkv+R+TitI3bUdlYFNW1wpKqNkehOCUGbAc1KAbfUW+SBMTkfnAkmqNu9NV20 9XxevWhfnUyQ7v7yMtmahHg5m0QGk7OuBctDdrKcxF85z0PSViYcg7TppuiKWKOLOmyS Ugy4wKqZNu5PHAC7HNR+oyh9HtoyO/TRd696vBDwWOQ7l7zVhO9q+RXwDFuKb05iuQfW x7GgUBB94P714PLZs01+hE85/EH4CF2zX9ygHbBzseP5siw+fygDt0hPiRWI9l8zYiqR h55ySNriQPr0d/Ld7Wp9lH8WnHk/0/IV/fn2nuwiXtgXkV9TEPrDNa4x8DVyEAC5374J Y8Ug== X-Gm-Message-State: ANoB5pl8tz3zn9FAfFf16Ezd4aZTeTKfPKtdrupiQV1HlZiskNMjYjAD qH41XCwYpz9elB/4vavo9MncjA== X-Google-Smtp-Source: AA0mqf78gRM3zma7ZP3Cy070W+sbXWWKNNRsCbOy5Iv8juBkB9xy5KIhg2Qcr76QN4KCFo1dK8075A== X-Received: by 2002:a65:5908:0:b0:46f:1e8f:1633 with SMTP id f8-20020a655908000000b0046f1e8f1633mr14878101pgu.556.1668497947573; Mon, 14 Nov 2022 23:39:07 -0800 (PST) Received: from [10.68.76.92] ([139.177.225.229]) by smtp.gmail.com with ESMTPSA id n63-20020a17090a5ac500b00200461cfa99sm10894663pji.11.2022.11.14.23.39.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Nov 2022 23:39:07 -0800 (PST) Message-ID: <82c9c89c-aee2-08a3-e562-359631bb0137@bytedance.com> Date: Tue, 15 Nov 2022 15:39:02 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [External] Re: [PATCH v2] mm: add new syscall pidfd_set_mempolicy(). To: Michal Hocko 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 References: <20221111084051.2121029-1-hezhongkun.hzk@bytedance.com> <20221111112732.30e1696bcd0d5b711c188a9a@linux-foundation.org> <3a3b4f5b-14d1-27d8-7727-cf23da90988f@bytedance.com> From: Zhongkun He In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668497950; a=rsa-sha256; cv=none; b=UwKSc9hKLavhI+8BcL8PWb47RVlAY1tubQFdKiSIowO3VWPE7R+tRfWX9KzMRiuptiRig+ 4B7bf0tjXpJVn0Vd07ptakVED+8TzKY/G5zkOs0BMLTmlEzsE4lN4zfKp0ORgoro9WTbYi eZaaL/eNzYv4RxqQNKQ48YIaQu7q0dw= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=H01TrKGh; spf=pass (imf15.hostedemail.com: domain of hezhongkun.hzk@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=hezhongkun.hzk@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668497950; 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=qrKxYxO/T/9+ij5BpZ+ZeE91vTMifnc8qboFL3OM2PU=; b=48oSmmB1LEg0RjNwXVP7c/NP4HjbDIUfcJ5rQMP12pwBIUc19rAiwVYiTDGe1JyPncI57v ym9oJ3OznBbs5m5ccxGZUYo8gUv/VO2XcQ45OKbgYWAM89f1UPovqgCM6dNRmOsmegm1OL TcvOEzGT2ipEusL0agf/Dv0s4wQf4r8= X-Stat-Signature: jop68tcjr94uechp3b39yqem5pq5hq1a X-Rspamd-Queue-Id: 05FFEA000C Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=H01TrKGh; spf=pass (imf15.hostedemail.com: domain of hezhongkun.hzk@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=hezhongkun.hzk@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1668497948-711533 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: >>> We shouldn't really rely on mmap_sem for this IMO. >> >> Yes, We should rely on mmap_sem for vma->vm_policy,but not for >> process context policy(task->mempolicy). > > But the caller has no way to know which kind of policy is returned so > the locking cannot be conditional on the policy type. Yes. vma->vm_policy is protected by mmap_sem, which is reliable if we want to add a new apis(pidfd_mbind()) to change the vma->vm_policy specified in pidfd. but not for pidfd_set_mempolicy(task->mempolicy is protected by alloc_lock). > > Yes this is all understood but the level of the overhead is not really > clear. So the question is whether this will induce a visible overhead. OK,i will try it. > Because from the maintainability point of view it is much less costly to > have a clear life time model. Right now we have a mix of reference > counting and per-task requirements which is rather subtle and easy to > get wrong. In an ideal world we would have get_vma_policy always > returning a reference counted policy or NULL. If we really need to > optimize for cache line bouncing we can go with per cpu reference > counters (something that was not available at the time the mempolicy > code has been introduced). > > So I am not saying that the task_work based solution is not possible I > just think that this looks like a good opportunity to get from the > existing subtle model. OK, i got it. Thanks for your reply and suggestions. Zhongkun.