]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs/ntfs3: Use kvmalloc instead of kmalloc(... __GFP_NOWARN)
authorKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Fri, 30 Jun 2023 12:12:58 +0000 (16:12 +0400)
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Thu, 28 Sep 2023 12:03:56 +0000 (15:03 +0300)
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
fs/ntfs3/attrlist.c
fs/ntfs3/bitmap.c
fs/ntfs3/super.c

index 42631b31adf17f39c635eacd3c0a8a033583d96b..7c01735d1219d858b46809147fa06dbcc6cafe4c 100644 (file)
@@ -52,7 +52,8 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)
 
        if (!attr->non_res) {
                lsize = le32_to_cpu(attr->res.data_size);
-               le = kmalloc(al_aligned(lsize), GFP_NOFS | __GFP_NOWARN);
+               /* attr is resident: lsize < record_size (1K or 4K) */
+               le = kvmalloc(al_aligned(lsize), GFP_KERNEL);
                if (!le) {
                        err = -ENOMEM;
                        goto out;
@@ -80,7 +81,17 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)
                if (err < 0)
                        goto out;
 
-               le = kmalloc(al_aligned(lsize), GFP_NOFS | __GFP_NOWARN);
+               /* attr is nonresident.
+                * The worst case:
+                * 1T (2^40) extremely fragmented file.
+                * cluster = 4K (2^12) => 2^28 fragments
+                * 2^9 fragments per one record => 2^19 records
+                * 2^5 bytes of ATTR_LIST_ENTRY per one record => 2^24 bytes.
+                *
+                * the result is 16M bytes per attribute list.
+                * Use kvmalloc to allocate in range [several Kbytes - dozen Mbytes]
+                */
+               le = kvmalloc(al_aligned(lsize), GFP_KERNEL);
                if (!le) {
                        err = -ENOMEM;
                        goto out;
index 107e808e06eae0068303c028d3c84c001f856142..d66055e30aff946d91d9959f519db8249383b731 100644 (file)
@@ -659,7 +659,8 @@ int wnd_init(struct wnd_bitmap *wnd, struct super_block *sb, size_t nbits)
                wnd->bits_last = wbits;
 
        wnd->free_bits =
-               kcalloc(wnd->nwnd, sizeof(u16), GFP_NOFS | __GFP_NOWARN);
+               kvmalloc_array(wnd->nwnd, sizeof(u16), GFP_KERNEL | __GFP_ZERO);
+
        if (!wnd->free_bits)
                return -ENOMEM;
 
index cfec5e0c7f66ae923ab13dc18e88d4cba86b7478..ea4e218c3f7553b0baed8e9ed8580e2cd8c42e4b 100644 (file)
@@ -1367,7 +1367,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
        }
 
        bytes = inode->i_size;
-       sbi->def_table = t = kmalloc(bytes, GFP_NOFS | __GFP_NOWARN);
+       sbi->def_table = t = kvmalloc(bytes, GFP_KERNEL);
        if (!t) {
                err = -ENOMEM;
                goto put_inode_out;