linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Gruenbacher <agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Trond Myklebust
	<trond.myklebust-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
Cc: Alexander Viro
	<viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org>,
	"Theodore Ts'o" <tytso-3s7WtUTddSA@public.gmane.org>,
	Andreas Dilger
	<adilger.kernel-m1MBpc4rdrD3fQ9qLvQP4Q@public.gmane.org>,
	"J. Bruce Fields"
	<bfields-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>,
	Jeff Layton <jlayton-vpEMnDpepFuMZCB2o+C8xQ@public.gmane.org>,
	Anna Schumaker
	<anna.schumaker-HgOvQuBEEgTQT0dZR+AlfA@public.gmane.org>,
	Dave Chinner <david-FqsqvQoI3Ljby3iVrkZq2A@public.gmane.org>,
	linux-ext4 <linux-ext4-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	XFS Developers <xfs-VZNHf3L845pBDgjK7y7TUQ@public.gmane.org>,
	Linux Kernel Mailing List
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Linux FS-devel Mailing List
	<linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Linux NFS Mailing List
	<linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Linux API Mailing List
	<linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH v13 45/51] sunrpc: Allow to demand-allocate pages to encode into
Date: Sun, 8 Nov 2015 23:19:35 +0100	[thread overview]
Message-ID: <CAHc6FU6mmJj0N6Jq1_fp59kv5h3XeuLUamfNg3iNo64=+rTYCA@mail.gmail.com> (raw)
In-Reply-To: <CAHQdGtQitLZq9fKHhzZbqS5ESRYNgNpw=M+y715mWMjFi-cgNQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

On Thu, Nov 5, 2015 at 4:57 PM, Trond Myklebust
<trond.myklebust-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org> wrote:
> On Thu, Nov 5, 2015 at 6:07 AM, Andreas Gruenbacher <agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
>> Trond,
>>
>> On Tue, Nov 3, 2015 at 5:25 PM, Trond Myklebust
>> <trond.myklebust-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org> wrote:
>>> On Tue, Nov 3, 2015 at 10:17 AM, Andreas Gruenbacher
>>> <agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
>>>> When encoding large, variable-length objects such as acls into xdr_bufs,
>>>> it is easier to allocate buffer pages on demand rather than precomputing
>>>> the required buffer size.
>>>
>>> NACK. We're not doing allocations from inside the XDR encoders. This
>>> can and should be done before calling into the SUNRPC layer.
>>
>> an XDR-encoded ACL can be up to 64k (16 pages) in size. In practice,
>> large ACLs like that will almost never occur and almost all ACLs will
>> fit into a single page though.
>>
>> The XDR-encoded ACL contains strings for the user and group names
>> which need to be looked up when the idmapper is used. Those lookups
>> are somewhat expensive; in addition, the lookup results can change
>> over time. When precomputing the size, allocating space, and then
>> encoding the ACL, we could run out of space when encoding.
>>
>> So we could always allocate the maximum 16 pages, encode the acl, and
>> free the unused pages. This would be rather wasteful though.
>>
>> Given how simple it is to allocate pages as we go, this seems the
>> better choice here. This doesn't break any existing code either; NULL
>> page pointers would have oopsed in xdr_get_next_encode_buffer before.
>>
>> From the memory management point of view, there is no difference in
>> preallocating GFP_NOFS pages and allocating them on demand; the pages
>> are allocated in the same task and locking context in both cases.
>>
>> So could you please explain why you object to this change?
>
> Allocating memory deep in the bowels of the RPC code with the
> expectation that it will be freed by the caller of the RPC request is
> a layering violation of the ugliest sort.

Ah, there we have it, Godwin's Law for software discussions.

What happens here is the following: the caller sets up an xdr_stream
that contains an array of NULL page pointers (__nfs4_proc_set_acl ->
nfs4_encode_acl -> xdr_init_encode_pages). It does so on purpose to
tell the XDR layer to allocate pages for it as needed, and it knows it
is responsible for later freeing those pages.

Without this patch, the XDR layer would immediately Oops when hitting
a NULL page pointer. This tells us that the XDR layer is so far not
prepared to handle NULL page pointers, and that we can assign a
meaning to NULL page pointers without affecting existing callers.

Using the existing XDR layer for XDR-encoding ACLs makes sense because
the XDR layer already knows how to align things, encode into multiple
pages, handle strings that wrap across pages, etc. I really don't want
to duplicate all that for ACLs.

> How is anyone who is
> unfamiliar with the code going to be able to understand what is going
> on without tracing through 1000 lines of code to spot where the
> allocation is happening?

Somebody unfamiliar with the existing code will not understand it
without putting some effort in, either. What do you expect? Besides,
the caller doesn't care where the allocation is happening, it just
cares that it is happening when it should.

> Aside from that, we do not want any non-critical blocking while
> holding the RPC socket lock. Your allocation request will block all
> further traffic to the server until it is satisfied. That includes
> blocking page writeback, which might actually free up memory to
> satisfy the allocation.
>
> As I said above, there is no reason whatsoever to have to do all this
> inside encode_setacl(). The entire ACL encoding into pages can be done
> before even calling into the RPC layer, just like we do today.

You have pointed that out before, and as a consequence, it was fixed
in the July 22 snapshot (https://lwn.net/Articles/652058/):

    * Changes to the nfs patches: acls are now encoded above the sunrpc
      layer. This means we can no longer encode small acls directly into the
      scratch area of an xdr_buf, we always have to allocate extra memory.
      But we also don't need to touch the nfs sunrpc code, which Trond objected
      to.

Since then, the ACL encoding happens in __nfs4_proc_set_acl, before
calling into the RPC layer.

Thanks,
Andreas

  parent reply	other threads:[~2015-11-08 22:19 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-03 15:16 [PATCH v13 00/51] Richacls Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 01/51] vfs: Add IS_ACL() and IS_RICHACL() tests Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 02/51] vfs: Add MAY_CREATE_FILE and MAY_CREATE_DIR permission flags Andreas Gruenbacher
     [not found]   ` <1446563847-14005-3-git-send-email-agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-11-04  2:33     ` Andreas Dilger
     [not found]       ` <507E7A63-024B-4EBD-B0C3-4ABE8280440F-m1MBpc4rdrD3fQ9qLvQP4Q@public.gmane.org>
2015-11-04  3:02         ` Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 03/51] vfs: Add MAY_DELETE_SELF and MAY_DELETE_CHILD " Andreas Gruenbacher
     [not found] ` <1446563847-14005-1-git-send-email-agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-11-03 15:16   ` [PATCH v13 04/51] vfs: Make the inode passed to inode_change_ok non-const Andreas Gruenbacher
2015-11-03 15:16   ` [PATCH v13 14/51] richacl: Check if an acl is equivalent to a file mode Andreas Gruenbacher
2015-11-03 15:16   ` [PATCH v13 19/51] vfs: Add richacl permission checking Andreas Gruenbacher
2015-11-03 15:16   ` [PATCH v13 22/51] xfs: Fix error path in xfs_get_acl Andreas Gruenbacher
2015-11-03 15:17   ` [PATCH v13 32/51] richacl: Set the other permissions to the other mask Andreas Gruenbacher
2015-11-03 15:17   ` [PATCH v13 36/51] nfsd: Keep list of acls to dispose of in compoundargs Andreas Gruenbacher
2015-11-03 15:17   ` [PATCH v13 51/51] nfs: Add support for the v4.1 dacl attribute Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 05/51] vfs: Add permission flags for setting file attributes Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 06/51] richacl: In-memory representation and helper functions Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 07/51] richacl: Permission mapping functions Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 08/51] richacl: Compute maximum file masks from an acl Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 09/51] richacl: Permission check algorithm Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 10/51] vfs: Cache base_acl objects in inodes Andreas Gruenbacher
     [not found]   ` <1446563847-14005-11-git-send-email-agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-11-03 22:29     ` Andreas Dilger
     [not found]       ` <D235953B-3EAF-4B00-AC07-4420B85E9E9E-m1MBpc4rdrD3fQ9qLvQP4Q@public.gmane.org>
2015-11-04 21:54         ` Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 11/51] vfs: Add get_richacl and set_richacl inode operations Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 12/51] vfs: Cache richacl in struct inode Andreas Gruenbacher
     [not found]   ` <1446563847-14005-13-git-send-email-agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-11-04  2:03     ` Andreas Dilger
2015-11-04 22:10       ` Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 13/51] richacl: Update the file masks in chmod() Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 15/51] richacl: Create-time inheritance Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 16/51] richacl: Automatic Inheritance Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 17/51] richacl: xattr mapping functions Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 18/51] richacl: Add richacl xattr handler Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 20/51] ext4: Add richacl support Andreas Gruenbacher
2015-11-04  2:13   ` Andreas Dilger
2015-11-04  2:19     ` Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 21/51] ext4: Add richacl feature flag Andreas Gruenbacher
2015-11-04  2:18   ` Andreas Dilger
     [not found]     ` <06282344-726E-49AD-936B-7BFF8F43B967-m1MBpc4rdrD3fQ9qLvQP4Q@public.gmane.org>
2015-11-04  2:28       ` Andreas Gruenbacher
2015-11-04  2:43         ` Andreas Gruenbacher
2015-11-03 15:16 ` [PATCH v13 23/51] xfs: Make xfs_set_mode non-static Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 24/51] xfs: Change how listxattr generates synthetic attributes Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 25/51] xfs: Add richacl support Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 26/51] xfs: Plug memory leak in xfs_attrmulti_attr_set Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 27/51] xfs: Fix richacl access by ioctl Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 28/51] richacl: acl editing helper functions Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 29/51] richacl: Move everyone@ aces down the acl Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 30/51] richacl: Propagate everyone@ permissions to other aces Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 31/51] richacl: Set the owner permissions to the owner mask Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 33/51] richacl: Isolate the owner and group classes Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 34/51] richacl: Apply the file masks to a richacl Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 35/51] richacl: Create richacl from mode values Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 37/51] nfsd: Use richacls as internal acl representation Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 38/51] nfsd: Add richacl support Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 39/51] nfsd: Add support for the v4.1 dacl attribute Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 40/51] nfsd: Add support for the MAY_CREATE_{FILE,DIR} permissions Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 41/51] richacl: Add support for unmapped identifiers Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 42/51] nfsd: Add support for unmapped richace identifiers Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 43/51] ext4: Don't allow unmapped identifiers in richacls Andreas Gruenbacher
     [not found]   ` <1446563847-14005-44-git-send-email-agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-11-04  2:20     ` Andreas Dilger
2015-11-03 15:17 ` [PATCH v13 44/51] xfs: " Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 45/51] sunrpc: Allow to demand-allocate pages to encode into Andreas Gruenbacher
2015-11-03 16:25   ` Trond Myklebust
     [not found]     ` <CAHQdGtScoRb-722ES168O8tkp-Rbvwe6bZ=70WwgiXpCC3vsHw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-11-05 11:07       ` Andreas Gruenbacher
     [not found]         ` <CAHc6FU5xkjWJeGFR5mO8+OAEMwwU6yWK7H8CV1fn5dk-LS23-g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-11-05 15:57           ` Trond Myklebust
     [not found]             ` <CAHQdGtQitLZq9fKHhzZbqS5ESRYNgNpw=M+y715mWMjFi-cgNQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-11-08 22:19               ` Andreas Gruenbacher [this message]
2015-11-03 15:17 ` [PATCH v13 46/51] sunrpc: Add xdr_init_encode_pages Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 47/51] nfs: Fix GETATTR bitmap verification Andreas Gruenbacher
2015-11-03 16:30   ` Trond Myklebust
2015-11-03 15:17 ` [PATCH v13 48/51] nfs: Remove unused xdr page offsets in getacl/setacl arguments Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 49/51] nfs: Distinguish missing users and groups from nobody Andreas Gruenbacher
2015-11-03 15:17 ` [PATCH v13 50/51] nfs: Add richacl support Andreas Gruenbacher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHc6FU6mmJj0N6Jq1_fp59kv5h3XeuLUamfNg3iNo64=+rTYCA@mail.gmail.com' \
    --to=agruenba-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=adilger.kernel-m1MBpc4rdrD3fQ9qLvQP4Q@public.gmane.org \
    --cc=anna.schumaker-HgOvQuBEEgTQT0dZR+AlfA@public.gmane.org \
    --cc=bfields-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org \
    --cc=david-FqsqvQoI3Ljby3iVrkZq2A@public.gmane.org \
    --cc=jlayton-vpEMnDpepFuMZCB2o+C8xQ@public.gmane.org \
    --cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-ext4-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=trond.myklebust-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org \
    --cc=tytso-3s7WtUTddSA@public.gmane.org \
    --cc=viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org \
    --cc=xfs-VZNHf3L845pBDgjK7y7TUQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).