mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jesse Barnes <jbarnes@virtuousgeek.org>
To: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Keith Packard <keithp@keithp.com>,
	Christoph Hellwig <hch@infradead.org>,
	Eric Anholt <eric@anholt.net>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Export shmem_file_setup and shmem_getpage for DRM-GEM
Date: Wed, 6 Aug 2008 17:45:31 -0700	[thread overview]
Message-ID: <200808061745.31594.jbarnes@virtuousgeek.org> (raw)
In-Reply-To: <200808051443.11858.nickpiggin@yahoo.com.au>

On Monday, August 4, 2008 9:43 pm Nick Piggin wrote:
> On Tuesday 05 August 2008 07:58, Keith Packard wrote:
> > On Mon, 2008-08-04 at 19:02 +1000, Nick Piggin wrote:
> > > > I suppose we could have user space allocate the shmem file (either
> > > > via tmpfs or sysv ipc). tmpfs suffers from the maxfd issue, while
> > > > sysv ipc runs up against the SHMMAX value.
> > >
> > > This is how I'd suggested it work as well. I think a little bit
> > > more effort should be spent looking at making this work.
> >
> > Well, I've spent a day thinking about using existing user-space APIs to
> > get at shmem files. While it's nice that we've discovered a
> > filesystem-independent mechanism to pin file pages, we haven't found
> > anything similar for creating the files. In particular, what I want is:
> >
> >  1) Anonymous files backed by swap
> >  2) Freed when the last process using them exits
> >  3) That never appear in the file system
> >  4) Do not consume a low FD (yeah, I know, rewrite the desktop)
> >
> > So, what I could do is
> >
> > 	char	template[] = "/dev/shm/drm-XXXXXX";
> > 	int	fd;
> > 	fd = mkstemp (template);
> > 	unlink (template);
> > 	ftruncate (fd, size)
> > 	object = drm_create_an_object_for_a_file (fd);
> > 	close (fd);
> >
> > While I haven't written any code yet, this should work and will even be
> > compatible with my current user-space API. I have to create a DRM object
> > for the file in any case, and so I don't need to hold onto the fd.
> > Releasing the fd also eliminates any ulimit issues.
> >
> > The drm_create_an_object_for_a_file call could return another fd. But,
> > note that the original shmem fd has no real value to the application in
> > this case.
> >
> > I can imagine other cases where mapping non-shmem files would make sense
> > though, in particular it's fairly easy to envision mapping an image file
> > to the GTT and having the graphics process decode and display it without
> > any additional copies. I think this demonstrates the potential utility
> > of the general file mapping operation.
> >
> > But, I'd like to have you reconsider whether it makes sense for user
> > space to go through the above dance to create anonymous shared objects
> > when the kernel already supports precisely the desired semantics and
> > even exposes them to the ipc/shm implementation.
>
> In my opinion, doing this little song and dance (which is a few lines
> of quite well defined APIs, btw) in userspace is preferable to adding
> a single line or exporting a single function in kernel space. Unless
> there is a better reason than eliminating a few lines of userspace code.
>
> I'm absolutely not against exporting a nice API for a swappable, object
> based memory allocator using ipc or shm to the wider kernel (with a nice
> API rather than just using shmem functions directly of course). But the
> fact that most or all of this seems to be able to be done in userspace
> just tells me that's where it should be prototyped first. It adds
> nothing to maintainence costs of the kernel code, and might actually be
> helpful to show some shortcomings of our user API definition or
> implementation.

Yeah, I like this approach too, but to echo what Keith & Dave already 
mentioned, it would make the in-kernel aspect of things much more difficult 
(without abusing VFS calls from within the kernel anyway).

It's not just the low level gfx libraries that need to create, map, operate 
on, and wait for objects.  The kernel also needs to create objects and map 
them at the very least (hopefully we can avoid most of the other stuff inside 
the kernel).

It seems like that's hard to do without duplicating big chunks of shmem.c.  
Any suggestions, Nick or Christoph?

I'm trying to think of analogues in other kernel subsystems, but the best I 
can come up with is shmem. :)  Some of the cluster fabric cards have similar 
issues (wanting to pin/map/unmap memory, and manage on-board IOMMUs) but I 
think gfx may be different in that it tends to use large chunks of memory for 
long periods of time; and even when a given GPU program is done with a piece 
of memory, the very next program run is likely to need it again.  And I think 
the in-kernel requirements in this case are fairly unique.

Jesse

  parent reply	other threads:[~2008-08-07  0:45 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-01  6:58 [PATCH] PCI: Add pci_read_base() API Eric Anholt
2008-08-01  6:58 ` [PATCH] Export shmem_file_setup and shmem_getpage for DRM-GEM Eric Anholt
2008-08-01  6:58   ` [PATCH] drm: Add GEM ("graphics execution manager") to i915 driver Eric Anholt
2008-08-01 15:44     ` Randy Dunlap
2008-08-01 18:11       ` Keith Packard
2008-08-06  1:11       ` Eric Anholt
2008-08-01  7:10   ` [PATCH] Export shmem_file_setup and shmem_getpage for DRM-GEM Eric Anholt
2008-08-01 10:57   ` Hugh Dickins
2008-08-01 18:06     ` Keith Packard
2008-08-01 20:50   ` Christoph Hellwig
2008-08-01 23:01     ` Keith Packard
2008-08-03 12:49       ` John Stoffel
2008-08-03 17:52         ` Keith Packard
2008-08-03 23:35           ` files/process scaling problem? (was: [PATCH] Export shmem_file_setup and shmem_getpage for DRM-GEM) Ingo Oeser
2008-08-04  0:19             ` Keith Packard
2008-08-04  8:19               ` Alan Cox
2008-08-04 13:51                 ` Arjan van de Ven
2008-08-04 14:11                   ` Alan Cox
2008-08-04 16:38                     ` Arjan van de Ven
2008-08-04 16:58                     ` Keith Packard
2008-08-04 21:46                       ` Ingo Oeser
2008-08-04 22:20                         ` Dave Airlie
2008-08-05  0:34                         ` Keith Packard
2008-08-11  1:23       ` [PATCH] Export shmem_file_setup and shmem_getpage for DRM-GEM Christoph Hellwig
2008-08-11  3:03         ` [PATCH] Export shmem_file_setup " Keith Packard
2008-08-04  1:54     ` [PATCH] Export shmem_file_setup and shmem_getpage " Keith Packard
2008-08-04  9:02       ` Nick Piggin
2008-08-04 10:26         ` Keith Packard
2008-08-04 10:43           ` Nick Piggin
2008-08-04 11:45             ` Keith Packard
2008-08-04 17:09               ` Hugh Dickins
2008-08-04 17:25                 ` Keith Packard
2008-08-04 18:39                   ` Hugh Dickins
2008-08-04 19:20                     ` Keith Packard
2008-08-04 19:55                       ` Hugh Dickins
2008-08-04 21:37                         ` Keith Packard
2008-08-05  2:25                         ` John Stoffel
2008-08-05  4:28                           ` Keith Packard
2008-08-06 16:20                             ` Stephane Marchesin
2008-08-06 17:24                               ` Arjan van de Ven
2008-08-06 17:32                                 ` Stephane Marchesin
2008-08-06 17:56                                   ` Keith Packard
2008-08-06 18:09                                     ` Stephane Marchesin
2008-08-06 21:22                                       ` Keith Packard
2008-08-07  2:16                                 ` Stephane Marchesin
2008-08-07  2:57                                   ` Keith Packard
2008-08-11  1:34                                 ` Christoph Hellwig
2008-08-05  4:28                 ` Nick Piggin
2008-08-11  1:30                 ` Christoph Hellwig
2008-08-04 21:58         ` Keith Packard
2008-08-04 22:22           ` Dave Airlie
2008-08-05  4:43           ` Nick Piggin
2008-08-05  5:19             ` Keith Packard
2008-08-07  0:45             ` Jesse Barnes [this message]
2008-08-19  1:17             ` Dave Airlie
2008-08-19 10:00               ` Nick Piggin
2008-08-19 16:46                 ` Keith Packard
2008-08-19 18:50                   ` Jesse Barnes
2008-08-21 13:42                     ` Jerome Glisse
2008-08-21 16:15                       ` Jesse Barnes

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=200808061745.31594.jbarnes@virtuousgeek.org \
    --to=jbarnes@virtuousgeek.org \
    --cc=eric@anholt.net \
    --cc=hch@infradead.org \
    --cc=keithp@keithp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nickpiggin@yahoo.com.au \
    /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

all inboxes | Powered by JetHome®