2

From LDD3 page 214:

GFP_NOIO
GFP_NOFS
These flags function like GFP_KERNEL, but they add restrictions on what the kernel can do to satisfy the request. A GFP_NOFS allocation is not allowed to perform any filesystem calls, while GFP_NOIO disallows the initiation of any I/O at all. They are used primarily in the filesystem and virtual memory code where an allocation may be allowed to sleep, but recursive filesystem calls would be a bad idea.

I want to know why recursive filesystem calls is a bad idea, when GFP_NOFS is masked?

Thanks!

Roman Zaitsev
  • 1,328
  • 5
  • 20
  • 28
dongdong
  • 25
  • 1
  • 4

1 Answers1

2

I want to know why recursive filesystem calls is a bad idea, when GFP_NOFS is masktd?

It's other way around: you use GFP_NOFS to signal, that allocation can sleep, but can't interact with filesystem ( for example: dump some memory block to disk to make some free memory ). It's done in critical areas of code.
For example: you entered filesystem call, locked some global mutex for this filesystem, called kmalloc. If kmalloc will try to call another filesystem function, that locks the same mutex - we will have deadlock. So we provide GFP_NOFS flag.

Roman Zaitsev
  • 1,328
  • 5
  • 20
  • 28
  • Hi Roman. thanks for your comments. So you mean there are some global mutex for the filesystem. One filesystem call kmalloc, if the kmalloc try to call another fileystem function, then there maybe the deadlock. while if there are enough pages, then kmalloc will not call another filesystem funcion, and everything will be ok, right? – dongdong Dec 30 '15 at 10:43
  • 1
    So you mean there are some global mutex for the filesystem - filesystem can be implemented like this. It's just an example. while if there are enough pages, then kmalloc will not call another filesystem funcion - I think, that kmalloc won't call filesystem function in case of enough pages, but without source code I can't be sure – Roman Zaitsev Dec 30 '15 at 10:46
  • Hi Roman. The GFP_NOFS flag is used to not interact with filesystem, as you said, maybe avoid deadlock. while for recursive filesystem calls, is there any problem? – dongdong Jan 04 '16 at 08:24
  • @dongdong see my example of possible problem. – Roman Zaitsev Jan 13 '16 at 09:02