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 7F4D8C6FD1D for ; Tue, 4 Apr 2023 12:34:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2E676B0074; Tue, 4 Apr 2023 08:34:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB79D6B0075; Tue, 4 Apr 2023 08:34:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B31A46B0078; Tue, 4 Apr 2023 08:34:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9E8316B0074 for ; Tue, 4 Apr 2023 08:34:47 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 774B8C0767 for ; Tue, 4 Apr 2023 12:34:47 +0000 (UTC) X-FDA: 80643652614.12.F5D7C10 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf21.hostedemail.com (Postfix) with ESMTP id 72EC11C0006 for ; Tue, 4 Apr 2023 12:34:44 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=TAlzRYiB; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=RFzj5oPi; spf=pass (imf21.hostedemail.com: domain of jack@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680611684; 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=SsWqIVQMlejDSW23EJAmwIj/GHRNWK6PJ/N+41zghf0=; b=501W46HEgPZOdZ60WN8hMq/2rChyEcgY0WghLicRVvx/qWd9CIr5Ul9ZCeB1XdG5U0ZZIG gvKR0EK2fj+PaiL0IMQJumuxwhXHHCeNQ1kbGzVHfqgGnASpcP55q5RYqgLbhd98JARqVq L0ceZmpabzoXtJca7CnK0iJkDVHv8oQ= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=TAlzRYiB; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=RFzj5oPi; spf=pass (imf21.hostedemail.com: domain of jack@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680611684; a=rsa-sha256; cv=none; b=ObEImnJnkz4gpEpgyyt6IYAxPfnkPghDFDJQ0DxTT2/EK6rYvQMl7kyVLwn2PB3jPuPUki BGCOt5dGb1jByQKqyLs6Npw3kQ6h7s7tTJSJ/Dk56ENCKAN4NHeSmYutQZJnNWT1t+LOQI MokNrIsZEX6oXhBKAwpJUOKQGRz02cc= 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 AA4192297B; Tue, 4 Apr 2023 12:34:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1680611682; 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=SsWqIVQMlejDSW23EJAmwIj/GHRNWK6PJ/N+41zghf0=; b=TAlzRYiBIjxaVMC6H76pOUtE2YdpkCpNIcr3pS4cDWzMs67s4lsnBvSOVeVUoyu/xUpNRG QDxXPlJa9jSZKhF1zpC6iPn2tId+S/s4LaMoVg75zZuG4v91vIrjmvJjEpw8/fMzqVlqQN hLH0Y7waEaM+6MiqNJYrqhOpR1HQzz4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1680611682; 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=SsWqIVQMlejDSW23EJAmwIj/GHRNWK6PJ/N+41zghf0=; b=RFzj5oPiX8/kqEb2S48gUC78Isi3jZVq+KosWDmavhuDbzFWW7Kb42kMuzbDMbbJI+1kTG b4FG03JuVXwgmNBA== 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 9B2BB13920; Tue, 4 Apr 2023 12:34:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wG/ZJWIZLGSRJQAAMHmgww (envelope-from ); Tue, 04 Apr 2023 12:34:42 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 15E0FA0732; Tue, 4 Apr 2023 14:34:42 +0200 (CEST) Date: Tue, 4 Apr 2023 14:34:42 +0200 From: Jan Kara To: cem@kernel.org Cc: hughd@google.com, jack@suse.cz, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, djwong@kernel.org Subject: Re: [PATCH 4/6] shmem: prepare shmem quota infrastructure Message-ID: <20230404123442.kettrnpmumpzc2da@quack3> References: <20230403084759.884681-1-cem@kernel.org> <20230403084759.884681-5-cem@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230403084759.884681-5-cem@kernel.org> X-Rspamd-Queue-Id: 72EC11C0006 X-Stat-Signature: p4f3hs7abb14jjo8izgqqji8eoxh7fk7 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1680611684-385032 X-HE-Meta: U2FsdGVkX18mgA0c37/6UBEdLulVeoXdCLFQ872zIpslEhYjc5VpAxY/GjlHOK3b27IZ8Av2bB84Ya4dG6METAXQSCXbxn5UWp18/8d881dwweiQGgE8r2xJE4aeNea8x4tac+702HVo+cEQCWqznFhz6tuBHitG2JxUuXI6JnrLXZ4gKg7BleNeHBpoG82QCuGRsU4bgh/io01ntBPCaJMQFtX0KvjfQzTlUwP3mfB2Kc7i09pAHjXq8DtVeAMVFo8VRUwxR2+wTlw7VRV2/25bQbU87EwXTBO6X/q87r5pfO51W+wS2HElklXBHIuiW96jt53DMjAO27gvPGNhn84zMdMnqshUyV+O5HybRr5ghdzGVE2EcWyighzIup5vx1jIpxwWzM6bLQ2SWRXBfGjJSZadkDaKPsZPrX15sh1xGVVh1/myTrlt6EPaxLnuxIVoTPs6pCl4wowUI6PJSjL9TZsdO+bvUyqFW66KyLndYG24AcU/otbCBFWQb9VwplnxvBKDF8wvN1BeVyTDyr8ieqP+vLn3BHXb8bSdkuNDWMHDyLV0stqTgLh19z5eV1omlqKRjVHheiQs5J9GCoxml1yVXasYM4B8QR4iCQb6ypgH4FUuEL35CqwvmOmgA8yy2+7pN6AUhSA7j5thLEwc55eLupDLfcaqEy7tXbdY2q4/cel7pD2YevtGzowH3qsWMPp/w1UwoBMV3TfYvt+R1urvgSWmQ1jibrVXHGqEBrEu6UkEPJxV9Gdy4t7LHOPK7edZAZ852mDPWkeIZBRVV7S0QqC5j9EPAUpaV9EuqC1jJBNyD+NeYXEkNryiDtVGj3CvFxNvcjwqEIy0/AfqDh5vUhYxgns/1ISlzigPegspRRU9eSsMp1wjCSlku7Cs4kkgr6h/jefYvhLR+O1pQJ5gQKg5nOdS6NiuVLzeH2Ep4XrOFJDf+Y2IyDKvUVvxjAA0L6b8FwynC2z 0ePF2Wt+ u9CbmgFHGi6uYqpOb63FkMvLnD8omZHIhJoigag8cn4780IwzXOizUL09w9uOAbJGB7ajKLijGxlAm3huX96F82ndOXX283eZ/NJvR+4kAWAmgwlULQwxsmDtOxDRCVcXSUy5Ki1bMASbJxa2LVijmtHLdDPFOFfOpuaSEwVZb1dsvUScBZe2RQOrUTr6AP1SN8+QEtmUH1HPnPz8zArGxYrZfYySsrK9zzsoAXHlBjMxL/xNDOVNoABmHwKEREPgu92Ao1H9DzCvjnWAOaPare2RS8Zurp4NOcZoM9eTPKylkBlQskpMuWC/Ypz1Nnb05yL+Ly07RSjW01faYiJ4/uTGmW4BxXHy7wk1 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 03-04-23 10:47:57, cem@kernel.org wrote: > From: Lukas Czerner > > Add new shmem quota format, its quota_format_ops together with > dquot_operations > > Signed-off-by: Lukas Czerner > Signed-off-by: Carlos Maiolino Just two small things below. > diff --git a/mm/shmem_quota.c b/mm/shmem_quota.c > new file mode 100644 > index 0000000000000..c415043a71e67 > --- /dev/null > +++ b/mm/shmem_quota.c ... > +/* > + * Load dquot with limits from existing entry, or create the new entry if > + * it does not exist. > + */ > +static int shmem_acquire_dquot(struct dquot *dquot) > +{ > + struct mem_dqinfo *info = sb_dqinfo(dquot->dq_sb, dquot->dq_id.type); > + struct rb_node **n = &((struct rb_root *)info->dqi_priv)->rb_node; > + struct rb_node *parent = NULL, *new_node = NULL; > + struct quota_id *new_entry, *entry; > + qid_t id = from_kqid(&init_user_ns, dquot->dq_id); > + struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); > + int ret = 0; > + > + mutex_lock(&dquot->dq_lock); > + > + down_write(&dqopt->dqio_sem); > + while (*n) { > + parent = *n; > + entry = rb_entry(parent, struct quota_id, node); > + > + if (id < entry->id) > + n = &(*n)->rb_left; > + else if (id > entry->id) > + n = &(*n)->rb_right; > + else > + goto found; > + } > + > + /* We don't have entry for this id yet, create it */ > + new_entry = kzalloc(sizeof(struct quota_id), GFP_NOFS); > + if (!new_entry) { > + ret = -ENOMEM; > + goto out_unlock; > + } > + > + new_entry->id = id; > + new_node = &new_entry->node; > + rb_link_node(new_node, parent, n); > + rb_insert_color(new_node, (struct rb_root *)info->dqi_priv); > + entry = new_entry; > + > +found: > + /* Load the stored limits from the tree */ > + spin_lock(&dquot->dq_dqb_lock); > + dquot->dq_dqb.dqb_bhardlimit = entry->bhardlimit; > + dquot->dq_dqb.dqb_bsoftlimit = entry->bsoftlimit; > + dquot->dq_dqb.dqb_ihardlimit = entry->ihardlimit; > + dquot->dq_dqb.dqb_isoftlimit = entry->isoftlimit; > + > + if (!dquot->dq_dqb.dqb_bhardlimit && > + !dquot->dq_dqb.dqb_bsoftlimit && > + !dquot->dq_dqb.dqb_ihardlimit && > + !dquot->dq_dqb.dqb_isoftlimit) > + set_bit(DQ_FAKE_B, &dquot->dq_flags); > + spin_unlock(&dquot->dq_dqb_lock); > + > + /* Make sure flags update is visible after dquot has been filled */ > + smp_mb__before_atomic(); > + set_bit(DQ_ACTIVE_B, &dquot->dq_flags); I'm slightly wondering whether we shouldn't have a dquot_mark_active() helper for this to hide the barrier details... > +out_unlock: > + up_write(&dqopt->dqio_sem); > + mutex_unlock(&dquot->dq_lock); > + return ret; > +} > + > +/* > + * Store limits from dquot in the tree unless it's fake. If it is fake > + * remove the id from the tree since there is no useful information in > + * there. > + */ > +static int shmem_release_dquot(struct dquot *dquot) > +{ > + struct mem_dqinfo *info = sb_dqinfo(dquot->dq_sb, dquot->dq_id.type); > + struct rb_node *node = ((struct rb_root *)info->dqi_priv)->rb_node; > + qid_t id = from_kqid(&init_user_ns, dquot->dq_id); > + struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); > + struct quota_id *entry = NULL; > + > + mutex_lock(&dquot->dq_lock); > + /* Check whether we are not racing with some other dqget() */ > + if (dquot_is_busy(dquot)) > + goto out_dqlock; > + > + down_write(&dqopt->dqio_sem); > + while (node) { > + entry = rb_entry(node, struct quota_id, node); > + > + if (id < entry->id) > + node = node->rb_left; > + else if (id > entry->id) > + node = node->rb_right; > + else > + goto found; > + } > + > + up_write(&dqopt->dqio_sem); > + mutex_unlock(&dquot->dq_lock); We should report some kind of error here, shouldn't we? We do expect to have the quota_id allocated from shmem_acquire_dquot() and we will be possibly loosing set limits here. Otherwise the patch looks good to me. Honza -- Jan Kara SUSE Labs, CR