Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1897816pxu; Fri, 18 Dec 2020 00:06:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKsvC8qi/AOwIMZmAaLzlaDDzkFikeeQh5EP8OUCPOyaMaVVlPNjLcL59l/V1z0fyPtO5E X-Received: by 2002:a17:906:e250:: with SMTP id gq16mr2733869ejb.382.1608278764370; Fri, 18 Dec 2020 00:06:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608278764; cv=none; d=google.com; s=arc-20160816; b=BYXrDw/lryDU5yGbfzvZ1+JZwW4E5YPCQdi1zirLbIqot0eStPraotLEUooJCgjbNU SEyKhed6Ow9HOmhRuGNm/djkRm8iqWIqRPdMEJksysEyXR1AkLnWijZsVhOz61MKM6JK mZy9L8WiAID3ViiWvRxHQ8/Jmk4OzmZILbj81FEAYL2TaWBKmjHOKvg2fR0wPBn2Zae9 KYcXIcE5m5AA1t8+VG3oW9pPyVL4kgYp8SRmVw8u7oHKPckA9SgCNWfRAtwW37Eyd87l e5dqko88y4q2EajxiKQ3WDJ9VLYbnlB3wNOapood6ORYBitnyzfqBlHsI+39MmYwiSTX mZIg== 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=DWXWwMxuO5VVgTeHS2MDsqO66san9FIaw5EJpdNOYwY=; b=t3wlPqPk8lSfBPNdc0cWUi7h9V+79U0u7ZnOoLaLAX7fY6kToEB2LoNV8dqnOLrLIA N8lEv+BIwZ+3BSnQOiJN7sNk4vS3PB+l6Okg2Z5UtUfa+/A/njxq4CJlIl3V3u3gEhZ2 6ToB3RsnAdXiOx3/wml+qsWu3KDMY0zLR9w8JMnB0NhLrEK8YcqfiHqDOHn0QlBQhjLd GFnHcROm77bR+3X0vEVzheKvmz9xgBTmsdHfqQpBQuBk7BwRIv9cyRQa4w3mAGxxERql EQ9ShLXacD7eTW813fRxpyfLGK8KrAqbK1zwylrfYptMiFXSi8fdlU/91Qj9evbAuJVw TQbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lT52rP0e; 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 lr3si4823788ejb.388.2020.12.18.00.05.42; Fri, 18 Dec 2020 00:06:04 -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=lT52rP0e; 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 S1732982AbgLRICM (ORCPT + 99 others); Fri, 18 Dec 2020 03:02:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725298AbgLRICL (ORCPT ); Fri, 18 Dec 2020 03:02:11 -0500 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27833C0617A7; Fri, 18 Dec 2020 00:01:28 -0800 (PST) Received: by mail-lf1-x134.google.com with SMTP id o13so3200232lfr.3; Fri, 18 Dec 2020 00:01:28 -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=DWXWwMxuO5VVgTeHS2MDsqO66san9FIaw5EJpdNOYwY=; b=lT52rP0ePFZFuLL4A4f+0puqMLAsNvs8IM2du26nu5GK85lcGZXB6g2+aeZnRU4PYX p/XGsGT8+RQvFOALsaaS6FLI7wdEsAlf5T0zRzE3q++LUytIajAVO//IAIzqee5Ym/cc SgznQo3koMaGw2jNODT8oNkVC+OrLDV13CUBQmX05J9830chh96vhqxCdtFkXrH/wzxU usQ9dwwHAOgOdad1wlfLDBJsUTKgGfFaRn2J3Wb+uP8rocOWHAAYb6qZcf7VZlUM0dwu lEFw4BeD/77Ag0tOVkXETcTuqA08il9WnsDKRQZQisDNEdgVx4KQVWiegNCgcwkRXHjQ 44LA== 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=DWXWwMxuO5VVgTeHS2MDsqO66san9FIaw5EJpdNOYwY=; b=AQB2vRV464rcIT+u9aAZMatO6SvXlJu+yGb+HAToRiguRfM2W4UDo/0Kmd82aRWAcf 6Yx4rwJjbcZ1dnoGu8coxo64WElrt63i8B/ZuvhT0XBApSyDFKgmZkz9sIx1NBuACQH0 m96jZMREdBzNGeWEMkJTPHEpBpCI020AUjymxBF56CrR1ej5n8HwBOItj/W9KMcuLavb Dzn8Tws2FXI4ss3FnqNYQSvtztWto5CT29ggzoJoGF7yUXyRKnnXRq2LqTNU+G79dxDY /AbpUSr/1ORPUt8Kt1eIOumjTiCbKiwz/TMZHc1Acy1PLp6PLgECTUJgcQ8mAjlIUfvA XFng== X-Gm-Message-State: AOAM533FWRyW0Zi6Dlzn6kwJl26w+srX40uIyo5kXUE1F7unToE4trpM f7xM4fisBfwKF5rx6yqC30ATCLTA3+zdlrekr8c0edjiDFVDsCJcF8E= X-Received: by 2002:a2e:9c82:: with SMTP id x2mr1298415lji.190.1608278486487; Fri, 18 Dec 2020 00:01:26 -0800 (PST) MIME-Version: 1.0 References: <3e97846b52a46759c414bff855e49b07f0d908fc.camel@themaw.net> <67a3012a6a215001c8be9344aee1c99897ff8b7e.camel@themaw.net> In-Reply-To: <67a3012a6a215001c8be9344aee1c99897ff8b7e.camel@themaw.net> From: Fox Chen Date: Fri, 18 Dec 2020 16:01:14 +0800 Message-ID: Subject: Re: [PATCH v2 0/6] kernfs: proposed locking and concurrency improvement To: Ian Kent Cc: Tejun Heo , Greg KH , akpm@linux-foundation.org, dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, miklos@szeredi.hu, ricklind@linux.vnet.ibm.com, sfr@canb.auug.org.au, viro@zeniv.linux.org.uk Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 18, 2020 at 3:36 PM Ian Kent wrote: > > On Thu, 2020-12-17 at 10:14 -0500, Tejun Heo wrote: > > Hello, > > > > On Thu, Dec 17, 2020 at 07:48:49PM +0800, Ian Kent wrote: > > > > What could be done is to make the kernfs node attr_mutex > > > > a pointer and dynamically allocate it but even that is too > > > > costly a size addition to the kernfs node structure as > > > > Tejun has said. > > > > > > I guess the question to ask is, is there really a need to > > > call kernfs_refresh_inode() from functions that are usually > > > reading/checking functions. > > > > > > Would it be sufficient to refresh the inode in the write/set > > > operations in (if there's any) places where things like > > > setattr_copy() is not already called? > > > > > > Perhaps GKH or Tejun could comment on this? > > > > My memory is a bit hazy but invalidations on reads is how sysfs > > namespace is > > implemented, so I don't think there's an easy around that. The only > > thing I > > can think of is embedding the lock into attrs and doing xchg dance > > when > > attaching it. > > Sounds like your saying it would be ok to add a lock to the > attrs structure, am I correct? > > Assuming it is then, to keep things simple, use two locks. > > One global lock for the allocation and an attrs lock for all the > attrs field updates including the kernfs_refresh_inode() update. > > The critical section for the global lock could be reduced and it > changed to a spin lock. > > In __kernfs_iattrs() we would have something like: > > take the allocation lock > do the allocated checks > assign if existing attrs > release the allocation lock > return existing if found > othewise > release the allocation lock > > allocate and initialize attrs > > take the allocation lock > check if someone beat us to it > free and grab exiting attrs > otherwise > assign the new attrs > release the allocation lock > return attrs > > Add a spinlock to the attrs struct and use it everywhere for > field updates. > > Am I on the right track or can you see problems with this? > > Ian > umm, we update the inode in kernfs_refresh_inode, right?? So I guess the problem is how can we protect the inode when kernfs_refresh_inode is called, not the attrs?? thanks, fox