[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v3 1/4] lib/vfscore: Use a scalable bitmap for open file descriptors


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 9 Sep 2019 12:57:59 +0300
  • Cc: sharan.santhanam@xxxxxxxxx
  • Delivery-date: Mon, 09 Sep 2019 09:58:18 +0000
  • Ironport-phdr: 9a23:q8OyPxYE3f3Qcml28uQZcqX/LSx+4OfEezUN459isYplN5qZr86+bnLW6fgltlLVR4KTs6sC17OM9fmwBydZsd6oizMrSNR0TRgLiMEbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpTEdFQ/iOgVrO+/7BpDdj9it1+C15pbffxhEiCCybL9vMhm6txjdu8oXjIdtN6o8yQbCr2dVdehR2W5mP0+YkQzm5se38p5j8iBQtOwk+sVdT6j0fLk2QKJBAjg+PG87+MPktR/YTQuS/XQcSXkZkgBJAwfe8h73WIr6vzbguep83CmaOtD2TawxVD+/4apnVAPkhSEaPDM/7WrZiNF/jLhDrRyhuRJx3oDaboKSOvV8cKPQZs8WSXZbU8pNTSFNHp+wYo0SBOQBJ+ZYqIz9qkMQoBu5HgmsGOLvyjlVjXHwwK06y/khGhzB0QM8GNIOq2jUrNTzNKsIVeC10bHIzSjYYvxKwjfx8pDIcg06rv2WR7JwdtPcxE8yHA3GllWdsZHpMjyI2ugXsGWW7/BsWfyxh2MlsQ18rCCjytojh4XUnI4YyVDJ+T9nzIs7K9C0UlN3bNG6HJZWqiqULZF5Qtk4TGFtoCs6z7oGtoOlcyUS05QnwgLfa+SAc4iV/hLvTOaRLil8hHJiYL+/mROy/lKhyu34TMW7zE1KojBdktnRrX8BzQbT6s+fRvt8+EeuxyqP2hjO5uxLPEw4j6nWJp47zrIuiJYes17PEyHulEXzlqCWd0Ek+uay6+TgZ7XrvoOTN4hvigHiM6QunNazAeAlMggWQmiW4viz1Kb58U3hXbVFlec6krPesJzCP8QUura5AxNJ0oYk8xu/Cjam0NIZnXkAN1JJYQ+IgJb3O17QJPD1FvO/g1W3kDd33PDKJLLgDYvLLnTZl7fhZ7l94VZGyAUv1dBf+45UCrYZLfLoWk/+rsbYAQU/MwCu2OboEtN91p8eWW2VBK+WKqbSvESO5u0xP+aMYJUaty3nJ/c7+v69xUM+zFoce6iuxt4bZW61GtxiIl6Fejz8j9FHFn0F7SQkS+m/o1qZTT9VL1KvR790sjo8E56nC8HHW5iwqLeamj+mFNtMYTYVWRi3DX70etDcCL83YyWIL5o5nw==
  • Ironport-sdr: W37x8ACUmsh7j0bAq3NSw3bRBbsKxfTdH8R9lp34SzvbizPZszNTui5DWPQyMD+7V96mAWSKfR uMWvsIH6soFQ==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Until now, the number of open file descriptors was limited to 64, which was the
number of bits of the underlying bitmap. We fix that by replacing with a
configurable bitmap. We set the default value of maximum open files to 1024.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 lib/vfscore/fd.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/vfscore/fd.c b/lib/vfscore/fd.c
index 01025a46..e09dd54c 100644
--- a/lib/vfscore/fd.c
+++ b/lib/vfscore/fd.c
@@ -35,19 +35,19 @@
 
 #include <string.h>
 #include <uk/essentials.h>
-#include <uk/bitops.h>
+#include <uk/bitmap.h>
 #include <uk/assert.h>
 #include <vfscore/file.h>
 #include <uk/plat/lcpu.h>
 #include <errno.h>
 #include <uk/ctors.h>
 
-#define FDTABLE_MAX_FILES (sizeof(uint64_t) * 8)
+#define FDTABLE_MAX_FILES 1024
 
 void init_stdio(void);
 
 struct fdtable {
-       uint64_t bitmap;
+       unsigned long bitmap[UK_BITS_TO_LONGS(FDTABLE_MAX_FILES)];
        uint32_t fd_start;
        struct vfscore_file *files[FDTABLE_MAX_FILES];
 };
@@ -59,14 +59,14 @@ int vfscore_alloc_fd(void)
        int ret;
 
        flags = ukplat_lcpu_save_irqf();
-       ret = ukarch_ffsl(~fdtable.bitmap);
+       ret = uk_find_next_zero_bit(fdtable.bitmap, FDTABLE_MAX_FILES, 0);
 
        if (!ret) {
                ret = -ENFILE;
                goto exit;
        }
 
-       fdtable.bitmap |= (uint64_t) 1 << ret;
+       uk_bitmap_set(fdtable.bitmap, ret, 1);
 
 exit:
        ukplat_lcpu_restore_irqf(flags);
@@ -83,7 +83,7 @@ void vfscore_put_fd(int fd)
        UK_ASSERT(fd > 2);
 
        flags = ukplat_lcpu_save_irqf();
-       __uk_clear_bit(fd, &fdtable.bitmap);\
+       uk_bitmap_clear(fdtable.bitmap, fd, 1);
        fp = fdtable.files[fd];
        fdtable.files[fd] = NULL;
        ukplat_lcpu_restore_irqf(flags);
@@ -129,7 +129,7 @@ struct vfscore_file *vfscore_get_file(int fd)
        UK_ASSERT(fd < (int) FDTABLE_MAX_FILES);
 
        flags = ukplat_lcpu_save_irqf();
-       if (!(fdtable.bitmap & ((uint64_t) 1 << fd)))
+       if (!uk_test_bit(fd, fdtable.bitmap))
                goto exit;
        ret = fdtable.files[fd];
        fhold(ret);
@@ -186,7 +186,7 @@ static void fdtable_init(void)
        memset(&fdtable, 0, sizeof(fdtable));
 
        /* reserve stdin, stdout and stderr */
-       fdtable.bitmap = 7;
+       uk_bitmap_set(fdtable.bitmap, 0, 3);
        init_stdio();
 }
 
-- 
2.20.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.