Skip to content

Commit fc471e3

Browse files
fs/ntfs3: Use kvmalloc instead of kmalloc(... __GFP_NOWARN)
Signed-off-by: Konstantin Komarov <[email protected]>
1 parent 06ccfb0 commit fc471e3

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

fs/ntfs3/attrlist.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)
5252

5353
if (!attr->non_res) {
5454
lsize = le32_to_cpu(attr->res.data_size);
55-
le = kmalloc(al_aligned(lsize), GFP_NOFS | __GFP_NOWARN);
55+
/* attr is resident: lsize < record_size (1K or 4K) */
56+
le = kvmalloc(al_aligned(lsize), GFP_KERNEL);
5657
if (!le) {
5758
err = -ENOMEM;
5859
goto out;
@@ -80,7 +81,17 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)
8081
if (err < 0)
8182
goto out;
8283

83-
le = kmalloc(al_aligned(lsize), GFP_NOFS | __GFP_NOWARN);
84+
/* attr is nonresident.
85+
* The worst case:
86+
* 1T (2^40) extremely fragmented file.
87+
* cluster = 4K (2^12) => 2^28 fragments
88+
* 2^9 fragments per one record => 2^19 records
89+
* 2^5 bytes of ATTR_LIST_ENTRY per one record => 2^24 bytes.
90+
*
91+
* the result is 16M bytes per attribute list.
92+
* Use kvmalloc to allocate in range [several Kbytes - dozen Mbytes]
93+
*/
94+
le = kvmalloc(al_aligned(lsize), GFP_KERNEL);
8495
if (!le) {
8596
err = -ENOMEM;
8697
goto out;

fs/ntfs3/bitmap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,8 @@ int wnd_init(struct wnd_bitmap *wnd, struct super_block *sb, size_t nbits)
659659
wnd->bits_last = wbits;
660660

661661
wnd->free_bits =
662-
kcalloc(wnd->nwnd, sizeof(u16), GFP_NOFS | __GFP_NOWARN);
662+
kvmalloc_array(wnd->nwnd, sizeof(u16), GFP_KERNEL | __GFP_ZERO);
663+
663664
if (!wnd->free_bits)
664665
return -ENOMEM;
665666

fs/ntfs3/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
13671367
}
13681368

13691369
bytes = inode->i_size;
1370-
sbi->def_table = t = kmalloc(bytes, GFP_NOFS | __GFP_NOWARN);
1370+
sbi->def_table = t = kvmalloc(bytes, GFP_KERNEL);
13711371
if (!t) {
13721372
err = -ENOMEM;
13731373
goto put_inode_out;

0 commit comments

Comments
 (0)